Jump to content

Recommended Posts

Posted

Hi. I was writing this simple VBS script and i would need help on how to insert triple double quotes in command.

I'm trying to run a program with WshShell.Run, but the problem is that i need to run the program under another user. As there's no WScript.RunAs (AFAIK), then i thought i would resort to using a command like this:

WshShell.Run Chr(34) & "runas /user:administrator "%programfiles%\app_path\app.exe"" & Chr(34)

The problem are those double quotes around the %programfiles%\app_path\app.exe part - you can't use them here for obvious reasons. I tried to use another Chr(34) instead of ", but it doesn't work.

Can anyone help me out?

Thanks


Posted (edited)

Here's an example that you may be able to adapt for your purposes. It's not pretty, but it works and I left it at that.

Set ws = WScript.CreateObject("WScript.Shell")
Set fs = CreateObject("Scripting.FileSystemObject")
sysdrv = ws.ExpandEnvironmentStrings ("%SYSTEMDRIVE%")
progdir = ws.ExpandEnvironmentStrings ("%PROGRAMFILES%")
windir = ws.ExpandEnvironmentStrings ("%SYSTEMROOT%")
defuser = sysdrv & "\Documents and Settings\Default User"
Set colDrives = fs.Drives
For Each objDrive in colDrives
       If fs.FileExists(objDrive.DriveLetter & ":\WIN51") Then strCD = objDrive.DriveLetter & ":\"
Next
strOEM = strCD & "OEM\"
str7Zcmd = windir & "\system32\7za.exe x -y -aoa " & strOEM

If fs.FileExists(strOEM & "\000_ProgFiles.7z") Then ws.Run(str7Zcmd & "\000_ProgFiles.7z -o" & """" & progdir & """"),0,True
If fs.FileExists(strOEM & "\000_DefaultUser.7z") Then ws.Run(str7Zcmd & "\000_DefaultUser.7z -o" & """" & defuser & """"),0,True

The last two lines should be of particular interest and unfortunately they also wrap around since they are so long. I'm sure someone here could come up with another way to accomplish this and it would look a lot better, but I needed this to work ASAP. Sometimes down and dirty is good enough :D

Edited by RogueSpear

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