Computer Hope

Microsoft => Microsoft DOS => Topic started by: TheHoFL on June 09, 2009, 04:48:05 PM

Title: Change screensaver registry remotely...
Post by: TheHoFL on June 09, 2009, 04:48:05 PM
Hello again...

I have now been given the task of pushing a screen saver to around 25 computers. Then i need to set the screen saver to be he default for all users.

I need to have a folder with a folder labeled "screen_saver" in it.

This is what i have...i know it looks as though a newb wrote it  :)

What is does is copy the screensaver file then needs t o set it as the default. I am just having issues with the remote registry part.  ???

Code: [Select]
copy /Y "screen_saver\newSS.scr" "\\timscomputer\c$\windows\System32"

REG ADD "\\timscomputer\HKCU\Control Panel\Desktop" /V SCRNSAVE.EXE /T REG_SZ /F /D "%SystemRoot%\System32\newSS.scr"

REG ADD "\\timscomputer\HKCU\Control Panel\Desktop" /V ScreenSaveActive /T REG_SZ /F /D 1

When running that i get the following:
Quote
        1 file(s) copied.
Press any key to continue . . .

Error:  A remote machine was specified, the root key must be HKLM or HKU.

Error:  A remote machine was specified, the root key must be HKLM or HKU.
Press any key to continue . . .

Can anyone assist me with this. I cannot find the key in HKLM for the screensaver.

Thank you guys and gals!
Title: Re: Change screensaver registry remotely...
Post by: BatchFileBasics on June 09, 2009, 04:52:21 PM
well im no genious with registry, but the error says :
Error:  A remote machine was specified, the root key must be HKLM or HKU.

you have it as:
REG ADD "\\timscomputer\HKCU\Control Panel\Desktop" /V SCRNSAVE.EXE /T REG_SZ /F /D "%SystemRoot%\System32\newSS.scr"
Title: Re: Change screensaver registry remotely...
Post by: TheHoFL on June 09, 2009, 04:55:40 PM
Hmmm.... very true. So i looked in HKU and there is a ".DEFAULT" string. I can drill down and find the keys. However i thought if i made that change there it would only effect the new user profiles that were created and do nothing with the already made user profiles?
Title: Re: Change screensaver registry remotely...
Post by: BC_Programmer on June 09, 2009, 05:00:08 PM
HKCU is HKEY_CURRENT_USER

HKU is HKEY_USERS

the problem here is that TheHoFL would then need to parse the crud in the HKEY_USERS key, and find out which one corresponds with the current user. (or, perhaps place it in all of them?) (I'm the sole user of my PC, and I have over 10 entries in there!)

really, a better method would be to simply put it in HKEY_LOCAL_MACHINE (HKLM)- or,  if possible, simply add a VBScript that will start up for each user, that copies the screensaver from a network drive (perhaps an unmapped share) to the local machine and sets it up locally (where it has access to HKEY_CURRENT_USER).



TO explore why this limitation exists, it seems quite obvious- you can perform remote registry procedures when no user is logged in! In which case, HKEY_CURRENT_USER is undefined. Additionally, it can easily change between calls, if somebody logs off and another logs back off, which can mean that the first half of registry entries go to one, and the second half to another account. Generally not a good thing!
Title: Re: Change screensaver registry remotely...
Post by: TheHoFL on June 09, 2009, 05:17:19 PM
I would much rather make the cahnge in HKLM, but i cannot find the string the key would be in, if there is one in there.
Title: Re: Change screensaver registry remotely...
Post by: BC_Programmer on June 09, 2009, 05:20:29 PM
oh, your right. there isn't one.

what about the idea of running a batch file at logon? and if you already do, it should be a simple change to that script.





Title: Re: Change screensaver registry remotely...
Post by: TheHoFL on June 09, 2009, 05:22:52 PM
That would be another excellent idea. I can not do that because we already have a logon.bat that is run at logon that is pushed from our home office location. They will not let us mess with it much. Do you know of any BAT file that could pull the users names and/or change a registry setting for every user profile on a remote computer?


EDIT: I tried remotely setting the regisrty setting in the following location and it did NOT apply to a profile that was already created. It did work when creating a new one though.
Code: [Select]
\\U1jbennett\HKU\.DEFAULT\Control Panel\Desktop
Title: Re: Change screensaver registry remotely...
Post by: BC_Programmer on June 09, 2009, 05:24:42 PM
well... it would be possible via VBScript.

But I'm too used to my own registry class in Visual Basic, so I'll have to do a little research on the VBScript methods for changing/enumerating registry data.

Are you able to use VBScript?
Title: Re: Change screensaver registry remotely...
Post by: TheHoFL on June 09, 2009, 05:26:00 PM
I suppose i could. VBS is fairly new to me though. So i may ask you some more newbie questions.  ;)
Title: Re: Change screensaver registry remotely...
Post by: BC_Programmer on June 09, 2009, 05:42:46 PM
well, VBScript might be out- because- get this-


it uses WMI, and I believe you recently disabled that?

oh the irony!  :P
Title: Re: Change screensaver registry remotely...
Post by: TheHoFL on June 09, 2009, 05:50:03 PM
No that was on a different group of computers.  :P
Title: Re: Change screensaver registry remotely...
Post by: BC_Programmer on June 09, 2009, 05:50:45 PM
Oh OK- maybe I can work out something with VBScript then.
Title: Re: Change screensaver registry remotely...
Post by: TheHoFL on June 09, 2009, 05:51:11 PM
Thank you so much for your help!
Title: Re: Change screensaver registry remotely...
Post by: BC_Programmer on June 09, 2009, 06:21:06 PM
OK, here's something to try:

Code: [Select]
Sub SetKeysForMachine(Byval MachineName)
const HKEY_USERS = &H80000003



strComputer = MachineName
Set StdOut = WScript.StdOut

stdout.WriteLine "Connecting to " & machineName

'Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
'MachineName & "\root\default:StdRegProv")
set oReg = GetObject("WinMgmts:{impersonationLevel=impersonate}!//" & strComputer & "/root/default:stdRegProv")
strKeyPath = ""
oReg.EnumKey HKEY_USERS, strKeyPath, arrSubKeys
'REG ADD "\\timscomputer\HKCU\Control Panel\Desktop" /V SCRNSAVE.EXE /T REG_SZ /F /D "%SystemRoot%\System32\newSS.scr"

'REG ADD "\\timscomputer\HKCU\Control Panel\Desktop" /V ScreenSaveActive /T REG_SZ /F /D 1
For Each subkey In arrSubKeys
    'StdOut.WriteLine subkey
    'save subkey\Control Panel\Desktop value, screensaveactive.
strKeyPath = subkey & "\Control Panel\Desktop"
strValueName = "ScreenSaveActive"
strValue = "1"
oReg.SetStringValue HKEY_USERS,strKeyPath,strValueName,strValue

oReg.SetStringvalue HKEY_USERS,Strkeypath,"SCRNSAVE.EXE", "%SystemRoot%\System32\newSS.scr"




Next

End Sub

Dim mmachineNames()
Const NumMachines =2
redim mmachinenames(NumMachines-1)

'Change this portion, to reflect the actual number of machines (the above constant) as well as their names.
mmachinenames(0) = "." 'this reflects the local machine. This was for my testing, change it :P
mmachinenames(1) = "SATELLITE"
on error resume next
Dim I ,X
'for each machine in mmachinenames
For I = 0 to ubound(mmachinenames)

SetKeysForMachine mmachinenames(I)
if err <> 0 then
wScript.stdOut.WriteLine "Error processing machine, " & mmachinenames(I)
Else
X=X+1
end if
next

wScript.stdOut.WriteLine "Script finished. Successfully processed " & X & " of " & ubound(mmachinenames)+1 & " Machines."

You'll still need to use the batch, to copy the screensaver. And then you can, instead of using REG ADD in your batch script, run "Cscript newscript.vbs"

remember, however, to modify the lines:

Code: [Select]
Const NumMachines =2

and


Code: [Select]
mmachinenames(0) = "." 'this reflects the local machine. This was for my testing, change it :P
mmachinenames(1) = "SATELLITE"

to reflect the names of the PCs your fiddling with on the network, as well as the number.


In my testing I was getting permission denied when it tried to change my laptop, "SATELLITE"'s, registry. I think it was simply the way I had things configured- not necessarily a network setup.

I hope the remote portions work for you. It reports the number that suceed after the script runs- (it doesn't quit of one fails, so if, say, one of the PCs is off, it won't simply stop there).

Title: Re: Change screensaver registry remotely...
Post by: gh0std0g74 on June 10, 2009, 03:49:18 AM
@BC, i didn't see OP's mentioned WMI is disabled (maybe i missed), if so, wouldn't the vbscript not work as it use WMI??
Title: Re: Change screensaver registry remotely...
Post by: patio on June 10, 2009, 04:12:36 AM
He mentioned disabling WMI on a group of machines in an earlier thread....
Title: Re: Change screensaver registry remotely...
Post by: BC_Programmer on June 10, 2009, 04:31:32 AM
@BC, i didn't see OP's mentioned WMI is disabled (maybe i missed), if so, wouldn't the vbscript not work as it use WMI??

He mentioned disabling WMI on a group of machines in an earlier thread....

I remembered that myself, which is why I checked  :)







well, VBScript might be out- because- get this-


it uses WMI, and I believe you recently disabled that?

oh the irony!  :P

No that was on a different group of computers.  :P
Title: Re: Change screensaver registry remotely...
Post by: TheHoFL on June 10, 2009, 09:36:15 AM
Thank you for the script BC_Programmer! I will give it a try.

EDIT: I have been searching, but i don't think it's possible. Could i use a wildcard in the registry.


I.E.
Code: [Select]

REG ADD "\\timscomputer\HKU\WILDCARD\Control Panel\Desktop" /V SCRNSAVE.EXE /T REG_SZ /F /D "%SystemRoot%\System32\newSS.scr"

I have tried a few but it just create a string with that name.  :(
Title: Re: Change screensaver registry remotely...
Post by: TheHoFL on June 10, 2009, 02:54:07 PM
Maybe i was doing it incorrectly. I am trying to get entry to be in every user profile. So i would need the script to somehow look up or place the reg key for every profile. Then i need to be able to add the computer names.

Quote
I.E. \\REMOTEPC\HKU\SID\Control Panel\Desktop" /V SCRNSAVE.EXE /T REG_SZ /F /D "%SystemRoot%\System32\ITEP SS_UTI Version.scr"
REG ADD "\\REMOTEPC\HKU\SID\Control Panel\Desktop" /V ScreenSaveActive /T REG_SZ /F /D 1

I just do not know how to have the code translate every SID to a user name. I did get it to work, just only for the ".DEFAULT" profile. This will only help me with new setups. I need to make these changes to computer that could have 20+ profiles on them. Any ideas?
Title: Re: Change screensaver registry remotely...
Post by: BC_Programmer on June 10, 2009, 04:12:01 PM
your supposed to change:

Code: [Select]
Const NumMachines =2
redim mmachinenames(NumMachines-1)

'Change this portion, to reflect the actual number of machines (the above constant) as well as their names.
mmachinenames(0) = "." 'this reflects the local machine. This was for my testing, change it :P
mmachinenames(1) = "SATELLITE"

that portion. right now, the mmachinesNames Array is being set to some test names (well, "." for local machine, and SATELLITE for my laptop.\\ change the 'NumMachines=2" to Nummachines=<number of PCs>, and mmachineNames to the proper PC names.

Oh and I have a teensy mistake in my script:

instead of
Code: [Select]
oReg.SetStringvalue HKEY_USERS,Strkeypath,"SCRNSAVE.EXE", "%SystemRoot%\System32\newSS.scr"

this should be:
Code: [Select]
oReg.SetValue(HKEY_USERS, strkeypath, "SCRNSAVE.EXE", REG_EXPAND_SZ, "%SystemRoot%\System32\newSS.scr"




Title: Re: Change screensaver registry remotely...
Post by: TheHoFL on June 10, 2009, 04:31:56 PM
Okay, i have make some changes. Also i cannot add it to HKCU, it needs to be in HKU. Can you please look over my changes? Do i need the underlined parts?

Quote
Sub SetKeysForMachine(Byval MachineName)
   const HKEY_USERS = &H80000003



   strComputer = MachineName
   Set StdOut = WScript.StdOut

   stdout.WriteLine "Connecting to " & machineName

   'Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
   'MachineName & "\root\default:StdRegProv")
   set oReg = GetObject("WinMgmts:{impersonationLevel=impersonate}!//" & strComputer & "/root/default:stdRegProv")
   strKeyPath = ""
   oReg.EnumKey HKEY_USERS, strKeyPath, arrSubKeys
    'REG ADD "\\timscomputer\HKCU\Control Panel\Desktop" /V SCRNSAVE.EXE /T REG_SZ /F /D "%SystemRoot%\System32\newSS.scr"

   'REG ADD "\\timscomputer\HKCU\Control Panel\Desktop" /V ScreenSaveActive /T REG_SZ /F /D 1
   For Each subkey In arrSubKeys

       'StdOut.WriteLine subkey
       'save subkey\Control Panel\Desktop value, screensaveactive.
      strKeyPath = subkey & "\Control Panel\Desktop"
      strValueName = "ScreenSaveActive"
      strValue = "1"
      oReg.SetStringValue HKEY_USERS,strKeyPath,strValueName,strValue

      oReg.SetValue(HKEY_USERS, strkeypath, "SCRNSAVE.EXE", REG_EXPAND_SZ, "%SystemRoot%\System32\newSS.scr"




   Next

End Sub

Dim mmachineNames()
Const NumMachines =2
redim mmachinenames(NumMachines-1)

'Change this portion, to reflect the actual number of machines (the above constant) as well as their names.
'mmachinenames(0) = "." 'this reflects the local machine. This was for my testing, change it :P
mmachinenames(0) = "testpc"
mmachinenames(1) = "imagepc"

on error resume next
Dim I ,X
'for each machine in mmachinenames
For I = 0 to ubound(mmachinenames)

   SetKeysForMachine mmachinenames(I)
   if err <> 0 then
         wScript.stdOut.WriteLine "Error processing machine, " & mmachinenames(I)
   Else
   X=X+1
   end if
next

wScript.stdOut.WriteLine "Script finished. Successfully processed " & X & " of " & ubound(mmachinenames)+1 & " Machines."
Title: Re: Change screensaver registry remotely...
Post by: BC_Programmer on June 10, 2009, 04:35:55 PM
you need the third underlined line. the first two are comments- they start with '.

I had them there, so I could remember what the keys where you wanted changed.

remember if you have more then 2 machines you can change the constant (Const NumMachines =2) to a higher number and add them where you now have "testpc" and "imagepc".


If net view reveals the names of the PCs you want to change somebody clever in the use of batch might be able to generate a base listing through manipulation of that output.
Title: Re: Change screensaver registry remotely...
Post by: TheHoFL on June 10, 2009, 05:01:23 PM
Now i am getting an error:

(http://img.photobucket.com/albums/v206/Michael_IStall/error.jpg)
Title: Re: Change screensaver registry remotely...
Post by: BC_Programmer on June 10, 2009, 05:05:04 PM
what is the entire script as it is now?
Title: Re: Change screensaver registry remotely...
Post by: TheHoFL on June 10, 2009, 05:10:28 PM
It says the error is in line 27. Here is line 27.
Code: [Select]
oReg.SetValue(HKEY_USERS, strkeypath, "SCRNSAVE.EXE", REG_EXPAND_SZ, "%SystemRoot%\System32\ITEP SS_UTI Version.scr"
Thank you so much for your assistance by the way! Do i actually need to change the "strikeypath" or do i leave that there?

Code: ... i changed file names and the test computer.

Code: [Select]
Sub SetKeysForMachine(Byval MachineName)
const HKEY_USERS = &H80000003



strComputer = MachineName
Set StdOut = WScript.StdOut

stdout.WriteLine "Connecting to " & machineName

'Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
'MachineName & "\root\default:StdRegProv")
set oReg = GetObject("WinMgmts:{impersonationLevel=impersonate}!//" & strComputer & "/root/default:stdRegProv")
strKeyPath = ""
oReg.EnumKey HKEY_USERS, strKeyPath, arrSubKeys
'REG ADD "\\timscomputer\HKCU\Control Panel\Desktop" /V SCRNSAVE.EXE /T REG_SZ /F /D "%SystemRoot%\System32\ITEP SS_UTI Version.scr"

'REG ADD "\\timscomputer\HKCU\Control Panel\Desktop" /V ScreenSaveActive /T REG_SZ /F /D 1
For Each subkey In arrSubKeys
    'StdOut.WriteLine subkey
    'save subkey\Control Panel\Desktop value, screensaveactive.
strKeyPath = subkey & "\Control Panel\Desktop"
strValueName = "ScreenSaveActive"
strValue = "1"
oReg.SetStringValue HKEY_USERS,strKeyPath,strValueName,strValue

oReg.SetValue(HKEY_USERS, strkeypath, "SCRNSAVE.EXE", REG_EXPAND_SZ, "%SystemRoot%\System32\ITEP SS_UTI Version.scr"




Next

End Sub

Dim mmachineNames()
Const NumMachines =1
redim mmachinenames(NumMachines-1)

'Change this portion, to reflect the actual number of machines (the above constant) as well as their names.
'mmachinenames(0) = "." 'this reflects the local machine. This was for my testing, change it :P
mmachinenames(0) = "u1jbennett"
on error resume next
Dim I ,X
'for each machine in mmachinenames
For I = 0 to ubound(mmachinenames)

SetKeysForMachine mmachinenames(I)
if err <> 0 then
wScript.stdOut.WriteLine "Error processing machine, " & mmachinenames(I)
Else
X=X+1
end if
next

wScript.stdOut.WriteLine "Script finished. Successfully processed " & X & " of " & ubound(mmachinenames)+1 & " Machines."
Title: Re: Change screensaver registry remotely...
Post by: BC_Programmer on June 10, 2009, 05:18:34 PM
ok, found the problem. also fixed something else.

Code: [Select]
Sub SetKeysForMachine(Byval MachineName)
const HKEY_USERS = &H80000003



strComputer = MachineName
Set StdOut = WScript.StdOut

stdout.WriteLine "Connecting to " & machineName

'Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
'MachineName & "\root\default:StdRegProv")
set oReg = GetObject("WinMgmts:{impersonationLevel=impersonate}!//" & strComputer & "/root/default:stdRegProv")
strKeyPath = ""
oReg.EnumKey HKEY_USERS, strKeyPath, arrSubKeys
'REG ADD "\\timscomputer\HKCU\Control Panel\Desktop" /V SCRNSAVE.EXE /T REG_SZ /F /D "%SystemRoot%\System32\ITEP SS_UTI Version.scr"

'REG ADD "\\timscomputer\HKCU\Control Panel\Desktop" /V ScreenSaveActive /T REG_SZ /F /D 1
For Each subkey In arrSubKeys
    'StdOut.WriteLine subkey
    'save subkey\Control Panel\Desktop value, screensaveactive.
strKeyPath = subkey & "\Control Panel\Desktop"
strValueName = "ScreenSaveActive"
strValue = "1"
oReg.SetStringValue HKEY_USERS,strKeyPath,strValueName,strValue
'Next line was changed:


oReg.SetValue(HKEY_USERS, strkeypath, "SCRNSAVE.EXE", REG_EXPAND_SZ, """%SystemRoot%\System32\ITEP SS_UTI Version.scr""")




Next

End Sub

Dim mmachineNames()
Const NumMachines =1
redim mmachinenames(NumMachines-1)

'Change this portion, to reflect the actual number of machines (the above constant) as well as their names.
'mmachinenames(0) = "." 'this reflects the local machine. This was for my testing, change it :P
mmachinenames(0) = "u1jbennett"
on error resume next
Dim I ,X
'for each machine in mmachinenames
For I = 0 to ubound(mmachinenames)

SetKeysForMachine mmachinenames(I)
if err <> 0 then
wScript.stdOut.WriteLine "Error processing machine, " & mmachinenames(I)
Else
X=X+1
end if
next

wScript.stdOut.WriteLine "Script finished. Successfully processed " & X & " of " & ubound(mmachinenames)+1 & " Machines."


this is the new line:

Code: [Select]
oReg.SetValue(HKEY_USERS, strkeypath, "SCRNSAVE.EXE", REG_EXPAND_SZ, """%SystemRoot%\System32\ITEP SS_UTI Version.scr""")
it didn't have a ) at the end. Also, since it has spaces, it will need to be quoted when placed in the registry. two quotes in a VBScript string equal one, which is why it has three on each end. Also, is the path correct? is the Screensaver in System32, or in a folder called "ITEP" in system32? (just checking ;))
Title: Re: Change screensaver registry remotely...
Post by: TheHoFL on June 10, 2009, 05:25:09 PM
The name of the file is "ITEP SS_UTI Version.scr" ... not my decision or there would be no spaces...

I am getting another error on the same line now. I didn't change anything this time.  ;)

error:
(http://img.photobucket.com/albums/v206/Michael_IStall/Screenshot_0064_06_10_2009.jpg)
Title: Re: Change screensaver registry remotely...
Post by: BC_Programmer on June 10, 2009, 05:27:21 PM
woops, my bad. Guess I' just too used to the VB6 IDE fixing these types of mistakes for me!  :P


change:

Code: [Select]
oReg.SetValue(HKEY_USERS, strkeypath, "SCRNSAVE.EXE", REG_EXPAND_SZ, """%SystemRoot%\System32\ITEP SS_UTI Version.scr""")


to

Code: [Select]
oReg.SetValue HKEY_USERS, strkeypath, "SCRNSAVE.EXE", REG_EXPAND_SZ, """%SystemRoot%\System32\ITEP SS_UTI Version.scr"""

Title: Re: Change screensaver registry remotely...
Post by: TheHoFL on June 10, 2009, 05:37:57 PM
Okay, now there are no errors. Now the issue is that i went to the machine that it should have changed and it did not change it. Any ideas? It should change the screen saver for every user even if the profile exists.

Thank you again for the help!

EDIT: when you double click the VBS it does not flash anything, it just has the "busy" mouse for a second.
Title: Re: Change screensaver registry remotely...
Post by: BC_Programmer on June 10, 2009, 06:06:56 PM
well- you should instead run it via the command line, using cscript.

this way it will report any issues changing the registry keys and/or connecting to the remote PC.

Also make sure that the remote PC has that set of keys permissions set to "full control" for "everybody".
Title: Re: Change screensaver registry remotely...
Post by: TheHoFL on June 11, 2009, 10:19:43 AM
Ok, i ran it from a BAT file and here is the results ...

Quote
        1 file(s) copied.
Press any key to continue . . .
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

Connecting to u1jbennett
Error processing machine, u1jbennett
Script finished. Successfully processed  of 1 Machines.
Press any key to continue . . .

Why would it say this
Quote
Error processing machine, u1jbennett
??


EDIT: I checked the registry on the remote machine and the registry for those setting were not changed.
Title: Re: Change screensaver registry remotely...
Post by: BC_Programmer on June 11, 2009, 10:22:42 AM
probably, a permission denied error.

 by default, XP only let's remote PC's Look at it's registry keys, not change them.


 But, the problem here, is that you would need to somehow change the permissions on all the machines, which would kind of make the script a moot point, unless you can find a way to automate that, as well.  :(
Title: Re: Change screensaver registry remotely...
Post by: TheHoFL on June 11, 2009, 10:31:00 AM
I am part of a domain admin group in AD. That group is the "administrators" group on the local machines. Wouldn't that give me the proper rights to the machine? Do you think there would be any difference if it was run from the DC?

I shouldn't need to use any of the switches i don't think...
Quote
Usage: CScript scriptname.extension [option...] [arguments...]
Options:
 //B         Batch mode: Suppresses script errors and prompts from displaying
 //D         Enable Active Debugging
 //E:engine  Use engine for executing script
 //H:CScript Changes the default script host to CScript.exe
 //H:WScript Changes the default script host to WScript.exe (default)
 //I         Interactive mode (default, opposite of //B)
 //Job:xxxx  Execute a WSF job
 //Logo      Display logo (default)
 //Nologo    Prevent logo display: No banner will be shown at execution time
 //S         Save current command line options for this user
 //T:nn      Time out in seconds:  Maximum time a script is permitted to run
 //X         Execute script in debugger
 //U         Use Unicode for redirected I/O from the console

This is the line that i have to call the script:
Code: [Select]
cscript "%~dp0\Itep_SS.vbs"
I noticed in the script there is a part that looks undefined...could that have something to do with it?
Code: [Select]
strKeyPath = ""
Title: Re: Change screensaver registry remotely...
Post by: BC_Programmer on June 11, 2009, 04:29:06 PM
I am part of a domain admin group in AD. That group is the "administrators" group on the local machines. Wouldn't that give me the proper rights to the machine? Do you think there would be any difference if it was run from the DC?

well, both the accounts on my laptop and my desktop were logged in as administrator, and it still gave me permission denied. we can find out exactly what the error number is though, to confirm.

change the line:

Code: [Select]
wScript.stdOut.WriteLine "Error processing machine, " & mmachinenames(I)

to

Code: [Select]
wScript.stdOut.WriteLine "Error processing machine, " & mmachinenames(I) & " error: " & err



Quote
I noticed in the script there is a part that looks undefined...could that have something to do with it?
Code: [Select]
strKeyPath = ""

Nope... that was on purpose.
Title: Re: Change screensaver registry remotely...
Post by: TheHoFL on June 11, 2009, 04:43:16 PM
Alright, I just changed it and ran the BAT that calls it.

Here is the results:

Quote
        1 file(s) copied.
Press any key to continue . . .
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

Connecting to u1jbennett
Error processing machine, u1jbennett error: 438
Script finished. Successfully processed  of 1 Machines.
Press any key to continue . . .

I looked it up and this was the description:
Quote
Object doesn't support this property or method
Title: Re: Change screensaver registry remotely...
Post by: BC_Programmer on June 11, 2009, 04:52:33 PM
ahh, 438.

odd.

Quote
Object doesn't support this property or method

Strange.

I tried the same script, changed the names of the PCs, and I got error 70 again, Permission denied.

There might be, a mistake copying it, though, the name of a method or somesuch.

Code: [Select]
Sub SetKeysForMachine(Byval MachineName)
const HKEY_USERS = &H80000003



strComputer = MachineName
Set StdOut = WScript.StdOut

stdout.WriteLine "Connecting to " & machineName

'Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
'MachineName & "\root\default:StdRegProv")
set oReg = GetObject("WinMgmts:{impersonationLevel=impersonate}!//" & strComputer & "/root/default:stdRegProv")
strKeyPath = ""
oReg.EnumKey HKEY_USERS, strKeyPath, arrSubKeys
'REG ADD "\\timscomputer\HKCU\Control Panel\Desktop" /V SCRNSAVE.EXE /T REG_SZ /F /D "%SystemRoot%\System32\ITEP SS_UTI Version.scr"

'REG ADD "\\timscomputer\HKCU\Control Panel\Desktop" /V ScreenSaveActive /T REG_SZ /F /D 1
For Each subkey In arrSubKeys
    'StdOut.WriteLine subkey
    'save subkey\Control Panel\Desktop value, screensaveactive.
strKeyPath = subkey & "\Control Panel\Desktop"
strValueName = "ScreenSaveActive"
strValue = "1"
oReg.SetStringValue HKEY_USERS,strKeyPath,strValueName,strValue
'Next line was changed:


oReg.SetValue KEY_USERS, strkeypath, "SCRNSAVE.EXE", REG_EXPAND_SZ, """%SystemRoot%\System32\ITEP SS_UTI Version.scr"""




Next

End Sub

Dim mmachineNames()
Const NumMachines =1
redim mmachinenames(NumMachines-1)

'Change this portion, to reflect the actual number of machines (the above constant) as well as their names.
'mmachinenames(0) = "." 'this reflects the local machine. This was for my testing, change it :P
mmachinenames(0) = "Satellite"
on error resume next
Dim I ,X
'for each machine in mmachinenames
For I = 0 to ubound(mmachinenames)

SetKeysForMachine mmachinenames(I)
if err <> 0 then
wScript.stdOut.WriteLine "Error processing machine, " & mmachinenames(I) & "Error:" & ERR 
Else
X=X+1
end if
next

wScript.stdOut.WriteLine "Script finished. Successfully processed " & Val(X) & " of " & ubound(mmachinenames)+1 & " Machines."

Also, make sure the WMI service "Windows Management Instrumentation" is running on both PCs.


I'll say this, this seemingly simply problem is becoming a real doozy!
Title: Re: Change screensaver registry remotely...
Post by: TheHoFL on June 11, 2009, 04:56:32 PM
Weird ... i copied the script you posted in your last post and this is what returned.

Quote
        1 file(s) copied.
Press any key to continue . . .
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

Connecting to Satellite
Error processing machine, SatelliteError:70
Press any key to continue . . .

And i made sure WMI was enabled.

You are totally correct... this is becoming a major pain! Thank you for helping me!  ;D
Title: Re: Change screensaver registry remotely...
Post by: BC_Programmer on June 11, 2009, 04:58:30 PM
hmm... you got permission denied.

But this time- you tried to connect to a fictitious "Satellite" on your network  :P

Sorry I had to change the PC name back to SATELLITE to test it over here. Try changing it back and see if you get the previous, 438 error again.
Title: Re: Change screensaver registry remotely...
Post by: TheHoFL on June 11, 2009, 05:06:00 PM
I am sorry i didn't notice you changed that. I am running on 4 hours of sleep today and it is catching up with me.  :-[ I changed it back and received the same error:

Quote
Connecting to u1jbennett
Error processing machine, u1jbennettError:438
Press any key to continue . . .
Title: Re: Change screensaver registry remotely...
Post by: BC_Programmer on June 11, 2009, 05:25:14 PM
well, I'll be honest...

I haven't got a clue what the heck is going on. the error made me think it was simply a typing mistake or something similar, but that isn't the case.

I did a few quick googles and the onlything I can think of, is if the other PC is running an OS before windows XP, the error might occur.
Title: Re: Change screensaver registry remotely...
Post by: TheHoFL on June 11, 2009, 05:29:15 PM
Bummer! Both are running XP Pro.

Well thank you soo much for your time! I really do appreciate it.  ;D
Title: Re: Change screensaver registry remotely...
Post by: BC_Programmer on June 11, 2009, 05:36:57 PM
Well, last ditch idea, is I could try to write a little VB6 program. Maybe my Registry class can cut through this WMI crap. It's written right to the API, none of this obtuse error crap.  ;D
Title: Re: Change screensaver registry remotely...
Post by: BC_Programmer on June 11, 2009, 05:50:02 PM
...

Well, I had it, but it gave me an idea, what is happening in the script.

When I debugged it, I found, that it was able to add the new key to every USER, except one, where it failed.

In my haste, I've forgotten that even the administrator is lower then the "SYSTEM" account, so chances are it crashes there.


I will add some error handling into the area where it loops through each one:


Code: [Select]
Sub SetKeysForMachine(Byval MachineName)
const HKEY_USERS = &H80000003



strComputer = MachineName
Set StdOut = WScript.StdOut

stdout.WriteLine "Connecting to " & machineName

'Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
'MachineName & "\root\default:StdRegProv")
set oReg = GetObject("WinMgmts:{impersonationLevel=impersonate}!//" & strComputer & "/root/default:stdRegProv")
strKeyPath = ""
oReg.EnumKey HKEY_USERS, strKeyPath, arrSubKeys

On Error Resume Next
For Each subkey In arrSubKeys
Err.clear
    'StdOut.WriteLine subkey
    'save subkey\Control Panel\Desktop value, screensaveactive.
strKeyPath = subkey & "\Control Panel\Desktop"
strValueName = "ScreenSaveActive"
strValue = "1"
oReg.SetStringValue HKEY_USERS,strKeyPath,strValueName,strValue
'Next line was changed:


oReg.SetValue KEY_USERS, strkeypath, "SCRNSAVE.EXE", REG_EXPAND_SZ, """%SystemRoot%\System32\ITEP SS_UTI Version.scr"""

If Err <> 0 then
stdout.WriteLine "Failed to change key " + strkeypath + " on machine " + Strcomputer
stdout.WriteLine "error was " + ERROR
end if


Next

End Sub

Dim mmachineNames()
Const NumMachines =1
redim mmachinenames(NumMachines-1)

'Change this portion, to reflect the actual number of machines (the above constant) as well as their names.
'mmachinenames(0) = "." 'this reflects the local machine. This was for my testing, change it :P
mmachinenames(0) = "Satellite"
on error resume next
Dim I ,X
'for each machine in mmachinenames
For I = 0 to ubound(mmachinenames)

SetKeysForMachine mmachinenames(I)
if err <> 0 then
wScript.stdOut.WriteLine "Error processing machine, " & mmachinenames(I) & "Error:" & ERR 
Else
X=X+1
end if
next

wScript.stdOut.WriteLine "Script finished. Successfully processed " & Val(X) & " of " & ubound(mmachinenames)+1 & " Machines."

Now, were the previous one, if it encountered an error, went back to the main procedure and complained to you, this one will continue on through the loop. It still complains though, and even more loudly!

Title: Re: Change screensaver registry remotely...
Post by: TheHoFL on June 11, 2009, 05:58:23 PM
Hmmm.... now i get the following:

Quote

        1 file(s) copied.
Press any key to continue . . .
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

Connecting to u1jbennett
Failed to change key .DEFAULT\Control Panel\Desktop on machine u1jbennett
error was
Failed to change key S-1-5-19\Control Panel\Desktop on machine u1jbennett
error was
Failed to change key S-1-5-19_Classes\Control Panel\Desktop on machine u1jbennet
t
error was
Failed to change key S-1-5-20\Control Panel\Desktop on machine u1jbennett
error was
Failed to change key S-1-5-20_Classes\Control Panel\Desktop on machine u1jbennet
t
error was
Failed to change key S-1-5-21-1130582348-1049843267-782984527-50788\Control Pane
l\Desktop on machine u1jbennett
error was
Failed to change key S-1-5-21-1130582348-1049843267-782984527-50788_Classes\Cont
rol Panel\Desktop on machine u1jbennett
error was
Failed to change key S-1-5-18\Control Panel\Desktop on machine u1jbennett
error was
Error processing machine, u1jbennettError:438
Press any key to continue . . .
Title: Re: Change screensaver registry remotely...
Post by: BC_Programmer on June 11, 2009, 06:01:33 PM
hmmm, thats 6 keys that failed- probably all of them.

Wow, you'd probably have better luck doing this manually!
Title: Re: Change screensaver registry remotely...
Post by: TheHoFL on June 11, 2009, 11:47:46 PM
/cry ... I'll maybe work on a BAT file running the the startup folder. The students are locked down from this area and shouldn't be able to make changes. Thank you so much for trying to get this to work for me. I really, really appreciate your time!

Have a good one!
Title: Re: Change screensaver registry remotely...
Post by: BC_Programmer on June 12, 2009, 08:59:24 AM
If it's any consolation, at least I perfected my registry Access routines for use with network PCs.
Title: Re: Change screensaver registry remotely...
Post by: TheHoFL on June 12, 2009, 09:37:48 AM
As long as we both learned something from the experience, then i say i was worth it!