Computer Hope
Microsoft => Microsoft Windows => Windows Vista and 7 => Topic started by: nothlit on September 15, 2010, 10:26:34 AM
-
Would anyone know how to make this work on Windows 7? Running the Script with admin rights doesn't work at least not in my testing. Start CMD in admin mode and then ran the vbs file from that CMD windows and it returns not admin. I'm half thinking it has something to do with this line ...
Set objComputer = GetObject("WinNT://" & strComputer & "")
But I have no idea how to fix it to work with Windows 7. It does work on XP.
On Error Resume Next
strTestUser = "TestUser"
strComputer = "."
Set objComputer = GetObject("WinNT://" & strComputer & "")
'Try to create test account
Set objUser = objComputer.Create("user", strTestUser)
objUser.SetPassword "blahblah"
objUser.SetInfo
'WScript.Echo Err.Number
If Err.Number <> 0 Then
WScript.Echo "Not an admin"
Else
WScript.Echo "Is an admin"
'Cleanup test account
objComputer.Delete "user", strTestUser
End If
-
If you are using a 64-bit version of windows you cannot use CreateObject() or GetObject() to create or acquire instances of COM objects.
I had a very similar problem (http://bc-programming.com/blogs/2010/04/the-mystery-of-the-broken-script/).
My solution was to use the 32-bit version of wscript or cscript, found in %systemroot%\syswow64\
-
:) :D Awesome ...
~bows down to your greatness~ Thanks for the help.