Skip to content
View in the app

A better way to browse. Learn more.

MSFN

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Help with VBS script

Featured Replies

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


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".

  • Author

Thanks - that work but it caused a few problems that i cant figure out myself.

When the script runs it does the following (see attachment)

any ideas?

thx in advance

post-42895-1160571343_thumb.jpg

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.

  • Author
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..........

Run filemon (from sysinternals) while you are running the script, and it should tell you both where the access denied occurs on the disk, and what user was attempting the operation.

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?

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

  • Author
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

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.

  • Author

Ill try to split them into 2 scripts and see what happens. How do i run it as a Group Policy computer startup script? Im currentl running via GP under Logon.

Thx

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.