Jump to content

Help with VBS script


Recommended Posts

I have this script which i want it to run as an administrator across a domain with users who and normal standard users

set WshShell = CreateObject("WScript.Shell")

WshShell.Run "runas /user:administrator@domain""cscript.exe \\server\share$\Script.vbs"""

WScript.Sleep 100

WshShell.Sendkeys "Password~"

' Uninstall games from Windows XP

'=============================================================================

Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")

Set WshShell = WScript.CreateObject("WScript.Shell")

sPrograms = WshShell.SpecialFolders("AllUsersPrograms")

If (Fso.FolderExists(sPrograms & "\Games")) Then

' Create file for uninstalling games

Set f = Fso.CreateTextFile("c:\windows\inf\wmdtocm.txt", True)

f.WriteLine("[Components]")

f.WriteLine("freecell=off")

f.WriteLine("hearts=off")

f.WriteLine("minesweeper=off")

f.WriteLine("msnexplr=off")

f.WriteLine("pinball=off")

f.WriteLine("solitaire=off")

f.WriteLine("spider=off")

f.WriteLine("zonegames=off")

f.Close

WshShell.Run "sysocmgr.exe /i:c:\windows\inf\sysoc.inf /u:""c:\windows\inf\wmdtocm.txt"" /q", 1, True

Fso.DeleteFolder(sPrograms & "\Games"), True

End If

Everything below ' Uninstall games from Windows XP works fine if i run as administrator so i guess the problem is with the runas script - can anyone help?

Thx

Link to comment
Share on other sites


You've left out a space in the runas statement:

WshShell.Run "runas /user:administrator@domain""cscript.exe \\server\share$\Script.vbs"""

This should be:

WshShell.Run "runas /user:administrator@domain ""cscript.exe \\server\share$\Script.vbs"""

Note the space after "administrator@domain".

Link to comment
Share on other sites

The "permission denied" error is generated by line 13 in the script. This is the line where you're trying to create the "c:\windows\inf\wmdtocm.txt" file, so presumably the user running the script doesn't have the necessary NTFS permissions to create the file.

Link to comment
Share on other sites

The "permission denied" error is generated by line 13 in the script. This is the line where you're trying to create the "c:\windows\inf\wmdtocm.txt" file, so presumably the user running the script doesn't have the necessary NTFS permissions to create the file.

Ok that sorts that but any idea on the other problem? as it happens only when a user logs on and only if they have games installed..........

Link to comment
Share on other sites

Ok that sorts that but any idea on the other problem? as it happens only when a user logs on and only if they have games installed..........

It looks like sysocmgr is started multiple times, but I can't figure out why that is happening. You'll have to be more specific. The first "runas" script is used to start the second script, right? So that second one is the "\\server\share$\Script.vbs" script, correct? What is the name of the first script and how does it get started?

Link to comment
Share on other sites

Add this to your script to see if it helps.

Dim WinD : WshShell.ExpandEnvironmentStrings("%Windir%")
Dim Cmd1 : Cmd1 = "sysocmgr.exe /i:" & WinD & "\inf\sysoc.inf /u:"
Dim Inf1 : Inf1 = WinD & "\inf\wmdtocm.txt")
WshShell.Run(Cmd1 & " " & Inf1), 1, True

Edited by gunsmokingman
Link to comment
Share on other sites

It looks like sysocmgr is started multiple times, but I can't figure out why that is happening. You'll have to be more specific. The first "runas" script is used to start the second script, right? So that second one is the "\\server\share$\Script.vbs" script, correct? What is the name of the first script and how does it get started?
i first had 2 scripts one had runas only and second had the main script (to remove games) i used the 1st script to run the 2nd script as administrator but it didnt work so i recreated this script including the runas command. When you see the line

WshShell.Run "runas /user:administrator@domain""cscript.exe \\server\share$\Script.vbs"""

this line is referring to the script itself in hope that it will run itself as admin (the UNC path is referring to itself) If im wrong and i can code this a different way pls advise.

Add this to your script to see if it helps.
Dim WinD : WshShell.ExpandEnvironmentStrings("%Windir%")
Dim Cmd1 : Cmd1 = "sysocmgr.exe /i:" & WinD & "\inf\sysoc.inf /u:"
Dim Inf1 : Inf1 = WinD & "\inf\wmdtocm.txt")
WshShell.Run(Cmd1 & " " & Inf1), 1, True

I added this line but it still didnt work. Could you explain where this code shodul be inserted?

Thanks guys

Link to comment
Share on other sites

i first had 2 scripts one had runas only and second had the main script (to remove games) i used the 1st script to run the 2nd script as administrator but it didnt work so i recreated this script including the runas command. When you see the line

WshShell.Run "runas /user:administrator@domain""cscript.exe \\server\share$\Script.vbs"""

this line is referring to the script itself in hope that it will run itself as admin (the UNC path is referring to itself) If im wrong and i can code this a different way pls advise.

Right, that's what I was afraid of... So the script starts and runs itself under an administrator account. Then that script again runs itself, and that script runs itself, and... You see where this is leading? Go back to using two scripts, or find a way to run the script with the required permissions. You could for instance run it as a Group Policy computer startup script.

Link to comment
Share on other sites

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...