Jump to content

Set background on a select group of computers using BGInfo


Recommended Posts

Posted

Hi all,

 

I have been asked to set a background/wallpaper on a group of computers on our curriculum network and this background will be different from the background on the rest of the network.

 

Currently we control the background via the tool BGInfo, I believe it is quite popular around here. This also requires a line or two in the login script. However the obvious problem here is that this couple of lines in the login script control the background for the entire network. Now I need a different background in a certain ICT Suite.

 

I'm guessing the only way to do this is adding some extra lines to the script to check what the computer name is and set the background / use the correct BGInfo command accordingly.

 

The computer names in question are IT-SUITE-27 to IT-SUITE-36.

 

Does anyone have any ideas of what script would be best in this case?

 

Thanks

 

James

Posted

set oShell=createobject("wscript.shell")

set oNet=createobject("wscript.network")

sComputer=ucase(oNet.computername")

sCmd="bginfo etc etc - non IT Suite"

if left(sComputer,8)="IT-SUITE" then

iNum=right(sComputer,2)

if iNum >=27 and iNum<=36 then

sCmd="bginfo etc etc IT Suite special"

end if

end if

oShell.run sCmd

 

Replace the lines starting "scmd" with the lines you want to happen for each position.

 

Basically, all the script does is get the computer name in upper case. If it starts with "IT-SUITE" then it takes the last 2 characters and checks the value. Note that this will all fall over if you have any machines like "IT-SUITEXX" (ie letters instead of numbers - has anyone been flash and numbered in hex, for example :-))

  • Thanks 1
Posted
Sorry... I forgot to mention it has to be done in batch script *looks embarassed for not mentioning that before* sorry! Thanks for the effort though.
Posted

OK; let's make life more difficult :-)

 

computername should be present as an environment variable; using the :~ construct allows you to extract part of it. this is a bit kludgy but should work.

 

to be honest, I'd start moving towards vbscript for stuff like this - it's a lot easier! Even if the main file is a batch file there's nothing to stop you putting:

 

cscript

 

in the cmd file to call out to a vbscript

 

@echo off

set cstart=%computername:~0,7%

if not %cstart%==IT-SUITE goto standard

cnumber=%computername:~7,2%

if cnumber==27 goto special

if cnumber==28 goto special

if cnumber==29 goto special

 

 

goto standard

:special

bginfo /special switches

goto end

 

:standard

bginfo /standard switches

 

:end

Posted

ace scripts Srochford, out of curiosity is the VB one someone I could run at logon or even in a workstation OU?

 

Tempted to work something like that out, different set backgrounds depending on department, but all changable centrally (hosted on the server). Be handy as I'm renaming all of our suite PCs over the summer :)

Posted

(Just putting them in code tags to make them easier to read)

 

VBScript:

 

set oShell=createobject("wscript.shell")
set oNet=createobject("wscript.network")
sComputer=ucase(oNet.computername")
sCmd="bginfo etc etc - non IT Suite"
if left(sComputer,8)="IT-SUITE" then 
iNum=right(sComputer,2)
if iNum >=27 and iNum<=36 then
  sCmd="bginfo etc etc IT Suite special"
end if
end if
oShell.run sCmd

 

Batch:

 

@echo off
set cstart=%computername:~0,7%
if not %cstart%==IT-SUITE goto standard
cnumber=%computername:~7,2%
if cnumber==27 goto special
if cnumber==28 goto special
if cnumber==29 goto special


goto standard
:special
bginfo /special switches
goto end

:standard
bginfo /standard switches

:end

Posted
ace scripts Srochford, out of curiosity is the VB one someone I could run at logon or even in a workstation OU?

 

Tempted to work something like that out, different set backgrounds depending on department, but all changable centrally (hosted on the server). Be handy as I'm renaming all of our suite PCs over the summer :)

 

It needs to run on a "per user" basis so running it at logon is fine. It's the kind of thing I have in a login script for all users (attached at domain level) - the script can then decide what you want to happen (eg on ours we don't change the wallpaper on a server but do change it on a workstation)

 

If you attach it to a workstation OU then you need to make sure you set the script as "user logon" not "machine startup". I don't like doing stuff at OUs unless it is very specific to an OU.

 

For example, we have an OU of "special PCs" (they are noticeboards, clocking in machines etc) and the stuff they run is very different from everything else. All other machines will do different things but it's essentially the same - eg you might want one wallpaper for group A but a different one for OU B but you still want a wallpaper everywhere.

Posted
Having read this thread I've just started using this nifty little app too. I packaged it up as an MSI in 5 mins and put a shortcut in the startup items
Posted

Okay, I tried using the batch version first of all and that just didn't work... all of the computers used the "non ict suite" BGInfo code.

 

So I tried the VBS version and got the following error:

 

"\\server\netlogon\bglogon.vbs(3, 36) Microsoft VBScript compilation error: Unterminated string constant"

 

This appeared to be due to a missing speech mark, which I added.

 

I then ran it again and got the following:

 

"\\server\netlogon\bglogon.vbs(4, 35) Microsoft VBScript compilation error: Syntax error"

 

Line 4 is actually the following:

sCmd="%SYSTEMROOT%\bginfo.exe /i"\\SERVER\NETLOGON\BGINFO\curric.bgi" /timer:0"

 

Any ideas? Is it the \\server bit? Or is it being affected by speech marks?

Posted

That line you've quoted suggests that the bginfo exe is in the systemroot. I know it isn't on my clients. Perhaps that's causing the problem?

 

I haven't actually tried this yet, still sorting out problems from my pupil servers HDDs breaking on Friday :(

Posted
It is in the systemroot. All the code related to BGInfo is correct, it just doesn't want to work when combined with the script from Steve :(.
Posted

You need to escape those quote characters in the middle of the string sCmd

 

sCmd="%SYSTEMROOT%\bginfo.exe /i"\\SERVER\NETLOGON\BGINFO\curric.bgi" /timer:0"

 

should read

sCmd="%SYSTEMROOT%\bginfo.exe /i""\\SERVER\NETLOGON\BGINFO\curric.bgi"" /timer:0"

 

Hope this helps,

 

Iain.

Posted

Just for info, bginfo will run from a server share - you don't need to install it on the machine or even copy it to the machine (but it won't do any harm if you have!)

 

Double double quotes is always a problem - one of the things I often do is put a:

 

wscript.echo sCmd

 

in a script while I'm testing it - this can then give you an idea of what's actually going to be run.

Posted

Ta very much!

 

Okay that means the error message disappears, but I'm back now with the same problem that I had with the batch script... it just doesn't work :(. It keeps setting it as the original background (i.e. the non it-suite one).

Posted

Kay, I have been playing about with the script a bit, but still can't get it working, even when I've cut half of the script out. I changed it so it should have just worked on my machine, but it still has the same result as above.

 

(i.e. I changed the script to the following:

 

set oShell=createobject("wscript.shell")

set oNet=createobject("wscript.network")

sComputer=ucase("oNet.computername")

sCmd="%SYSTEMROOT%\bginfo.exe /i""\\SERVER\NETLOGON\BGINFO\curric.bgi"" /timer:0"

if sComputer="IT-TECH-02" then

sCmd="%SYSTEMROOT%\bginfo.exe /i""\\SERVER\NETLOGON\BGINFO\curric-web.bgi"" /timer:0"

end if

oShell.run sCmd

 

The only effect this had on my machine (IT-TECH-02) was to set the background as curric.bgi :(.

 

Also the following doesn't work on my machine:

 

set oShell=createobject("wscript.shell")

set oNet=createobject("wscript.network")

sComputer=ucase("oNet.computername")

sCmd="%SYSTEMROOT%\bginfo.exe /i""\\SERVER\NETLOGON\BGINFO\logoff.bgi"" /timer:0"

if right(sComputer,2)="02" then

sCmd="%SYSTEMROOT%\bginfo.exe /i""\\SERVER\NETLOGON\BGINFO\logoff-web.bgi"" /timer:0"

end if

oShell.run sCmd

 

 

I'm guessing the value of sComputer isn't what we think it is?

Posted

do you have the microsoft script debugger installed? If so, use it :-)

 

It's at http://www.microsoft.com/downloads/details.aspx?FamilyID=2f465be0-94fd-4569-b3c4-dffdf19ccd99&displaylang=en (if that link doesn't work google for scd10en.exe)

 

When it's installed, run your script by typing:

 

.vbs //x

 

This will launch it in the debugger and you can step through it to see what's going on. The toolbar buttons are not terribly intuitive but the tool tip on one of them is "step into" - click this to step through the program one line at a time. You can click on any line and press F9 to set a breakpoint; if you now press F5 the code will run to that point and then stop. When it's stopped you can open the command window (from the view menu) and check variable values - eg type ?computername to see the value scomputer has.

 

You can also add lines like:

 

wscript.echo sComputer

 

to see the value it has (you probably want to change the default host to cscript to do this - cscript //h:cscript - otherwise you get popups for every "echo")

Posted

Okay, just an update on this, I got it working. It was my own fault...

 

One of the lines was origally given as:

 

sComputer=ucase(oNet.computername")

 

As you can see, there is one speech mark there. I noticed it was wrong but instead of thinking that it shouldn't actually be there, I assumed it's partner had been missed out and added it. This obviously sets the exact value of sComputer to be "oNet.computername". I took the speech marks out and it works perfectly.

 

Thanks once again Steve! It's a brilliant script.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...