Hi,
Here's my problem:
I want to shedule on legacy Windows Servers (Windows 2000 Servers) to run
the Sysinternals contig.exe application, which is very useful and powerful to
defragment drives and folders.
But before running the contig.exe, you have to accept the EULA by clicking
on the "I accept" button of a pop-up window. Once accepted, several keys and
a dword are added to the registry.
I want to schedule this task by using a "special user" allowed to connect as
a batch job only. It doesn't have any profile, and, very important, doesn't
have any keys in the registry under the HKEY_USERS.
Once running this script for the first time by the scheduler, the EULA
pop-up is not displayed, so no new keys can be added to the registry, and
then the script cannot run and waits for the click on the "I accept the EULA"
button.
My goal is to create automatically the keys and the dword value before the
schedule task runs this script, and then the EULA will be already accepted
without clicking on this button.
Can someone explain me why in the following script, the creation of the keys
and the value is not working. Thanks a lot.
The steps are:
1 - getting the SID of my special user
2 - creating the key with the SID under HKEY_Users
3 - creating all the key and subkeys for the Sysinternals contig application
4 - creating the new dword named "EulaAccepted" with a value of '1'
----------------------------------------------------
' Get the Account SID of the user used by the scheduler
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objAccount =
objWMIService.Get("Win32_UserAccount.Name='user',Domain='domain'")
accountSID = objAccount.SID
' Add the reg entry so it accepts the Sysinternals EULA
Const HKEY_USERS = &H80000003
Set StdOut = WScript.StdOut
Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &
strComputer & "\root\default:StdRegProv")
strKeyPath = accountSID
Wscript.Echo "Creating the key with the SID: " & strKeyPath
objReg.CreateKey HKEY_USERS,strKeyPath
strKeyPath = strKeyPath & "\Software"
Wscript.Echo "Creating the key with Software: " & strKeyPath
objReg.CreateKey HKEY_USERS,strKeyPath
strKeyPath = strKeyPath & "\Sysinternals"
Wscript.Echo "Creating the key with Sysinternals: " & strKeyPath
objReg.CreateKey HKEY_USERS,strKeyPath
strKeyPath = strKeyPath & "\C"
Wscript.Echo "Creating the key with C: " & strKeyPath
objReg.CreateKey HKEY_USERS,strKeyPath
strEntryName = "EulaAccepted"
dwValue = 1
Wscript.Echo "Setting the value of " & strEntryName & " to " & dwValue
objReg.SetDWORDValue HKEY_USERS,strKeyPath,strEntryName,dwValue
objReg.GetDWORDValue HKEY_USERS,strKeyPath,strEntryName,dwValue
Wscript.Echo strEntryName & " = " & dwValue
------------------------------------------------------
And here's the output:
==============================
accountSID = S-1-5-21-2304659736-2020637620-97400744-1039
Creating the key with the SID: S-1-5-21-2304659736-2020637620-97400744-1039
Creating the key with Software:
S-1-5-21-2304659736-2020637620-97400744-1039/Software
Creating the key with Sysinternals:
S-1-5-21-2304659736-2020637620-97400744-1039\Software\Sysinternals
Creating the key with C:
S-1-5-21-2304659736-2020637620-97400744-1039\Software\Sysinternals\C
Setting the value of EulaAccepted to 1
EulaAccepted =
===================================
Nothing is created in the registry.
I am a local administrator of my server (not attached to any domain).
Thanks again for your help.
Yann