Escaping special characters in run with administrator privileges script

Hello, reviving an old one on this forum:
I used this script:
Here is a VB Script Vall Script that will get around the Password Prompt when "RunAs" is called...



' To Run other VB Scripts or even Batch Files with Admin Priviliges'


Dim WshShell, objFSO

suser = ""

sPass = "YourPassWord"


'Put your Domain Account and Password in between the qoutes, REMEMBER! the Password will be clear text. If this is a standalone just take off the


sCommand = "wscript \UNCServerNameShareFolderYourScript.vbs"


'This will be the path were the scripted you want called will be at. Please note you can substitute the ablove for a local directory (Example: C:FolderYourScript.vbs)


Set objComputer = CreateObject("Shell.LocalMachine")

Set WshNetwork = CreateObject("WScript.Network")

Set WshShell = CreatObject("WScript.Shell")

Set WshEnv = wshShell.Environment("Process")

WinPath = WshEnv("SystemRoot")&"System32runas.exe"

rc = WshShell.Run ("runas /noprofile /user:" & suser & " " $ Chr(34) & sCommand & Chr(34))

WScript.Sleep 900

WshShell. AppActivate(WinPath)




Now my problem: my users account name is:



When running above proposed script, I get the following error:

Windows Script Host

Script: C:VBSCstartMA.vbs

Line: 20

Character: 60

Error: Invalid character

Code: 800A0408

Source: Microsoft VBScript compilation error.


My guess is that my users name User's is giving troubles. I tried a few combinations, but I keep getting this error.


Last thing I tried is:


Dim WshShell, objFSO

suser = "user"& chr(7) &"s" 

sPass = "welkom"


Also tried: suser = "user's" and "user"'"s" or  even  "user""& chr(7) &""s" and "user& chr(7) &s"...

As you can see, I don't know squad ;p

Could you help me out? I just wanna run the following Start Menu Cleanup script:


'#============================================================================== '# SCRIPT.........: CleanUpStartMenuItems.vbs '# AUTHOR.........: Stuart Barrett '# VERSION........: 1.0 '# CREATED........: 11/11/11 '# LICENSE........: Freeware '# REQUIREMENTS...: '# '# DESCRIPTION....: Cleans up any Start Menu folders containing broken '# shortcuts '# '# NOTES..........: Untested on Windows 7!! '# '# Will ask before deleting any folders (can be amended '# as per noted in script) '# '# You can add as many excluded folders as required. '# '# CUSTOMIZE......: '#============================================================================== '# REVISED BY.....: '# EMAIL..........: '# REVISION DATE..: '# REVISION NOTES.: '# '#============================================================================== '#============================================================================== Set objShell = CreateObject("WScript.Shell") Set objFSO = CreateObject("Scripting.FileSystemObject") strStartMenu = objShell.SpecialFolders("StartMenu") strAllUsersStartMenu = objShell.SpecialFolders("AllUsersStartMenu") '#-------------------------------------------------------------------------- '# Add Any Excluded Folders in here. You will also need to increase the '# arrExcludedFolders(x) array variable by 1. '#-------------------------------------------------------------------------- Dim arrExcludedFolders(3) arrExcludedFolders(0) = "programs" arrExcludedFolders(1) = "programsaccessories*" arrExcludedFolders(2) = "programsadministrative tools" '#-------------------------------------------------------------------------- DeleteStartMenuItems strStartMenu, 0 DeleteStartMenuItems strAllUsersStartMenu, 1 '#-------------------------------------------------------------------------- '# SUBROUTINE.....: DeleteStartMenuItems(strFolder, intStartMenu) '# PURPOSE........: Deletes all the folders with broken shortcuts in '# the specified folder '# ARGUMENTS......: strFolder = full path to the folder '# intStartMenu = index of Start Menu type '# EXAMPLE........: DeleteStartMenuItems("c:documents and settingsall usersstart menu", 0) '# NOTES..........: intStartMenu Values: '# 0 = Start Menu '# 1 = All Users Start Menu '#-------------------------------------------------------------------------- Sub DeleteStartMenuItems(strFolder, intStartMenu) On Error Resume Next booDelete = 0 booCheck = 1 Set objFolder = objFSO.GetFolder(strFolder) If intStartMenu = 0 Then strSM = strStartMenu Else strSM = strAllUsersStartMenu End If For i = 0 To UBound(arrExcludedFolders) - 1 strExcludedFolder = strSM & arrExcludedFolders(i) If LCase(strFolder) = LCase(strSM) Then booCheck = 0 Exit For End If If Right(strExcludedFolder, 2) = "*" Then strExcludedFolder = Left(strExcludedFolder, Len(strExcludedFolder) - 2) If InStr(LCase(strFolder), LCase(strExcludedFolder)) > 0 Then booCheck = 0 Exit For End If Else If InStr(LCase(strExcludedFolder) & "||", LCase(strFolder) & "||") > 0 Then booCheck = 0 Exit For End If End If Next If booCheck = 1 Then For Each objItem In objFolder.Files strFullName = objFSO.GetAbsolutePathName(objItem) If Right(LCase(objItem), 3) = "lnk" Then Set objShortcut = objShell.CreateShortcut(strFullName) strTarget = LCase(objShortcut.TargetPath) If NOT objFSO.FileExists(strTarget) Then '#-------------------------------------------------------------------------- '# Currently set up to ask on each folder deletion. To remove prompting '# before deletion (risky) uncomment out the next line and comment out '# ( ' ) the rest up to '#----- line below. '#-------------------------------------------------------------------------- 'booDelete = 1 DeletePrompt = MsgBox("Do you wish to delete the below Start Menu folder? " & _ vbCrLf & vbCrLf & objFolder & " ", vbQuestion+vbYesNo, "CleanUp Start Menu Items") Err.Clear If DeletePrompt = vbYes Then booDelete = 1 Exit For End If '#-------------------------------------------------------------------------- End If End If Next If booDelete = 1 Then objFolder.Delete True End If For Each objItem In objFolder.SubFolders DeleteStartMenuItems objItem.Path, intStartMenu Next  [/pre] End Sub


Thank you in advance...

And Peace!


[[User:Devnullius|Devnullius]] [[User:Devnullius|Devnullius]]

Cuisvis hominis est errare, nullius nisi insipientis in errore persevare —— All spelling mistakes are my own and may only be distributed under the GNU General Public License! – (© 95-1 by Coredump; 2-012 by DevNullius)


Software/Hardware used:
vista x86

Answer Wiki

Thanks. We'll let you know when a new response is added.

Hello, everybody, the good shoping place, the new season approaching, click in.
Welcome to ==== ==
Air Jordan (1-24) shoes $35
Jordan (1-22)&2009 shoes $45
Nike shox (R4, NZ, OZ, TL1, TL2, TL3) $35
Handbags ( Coach Lv fendi D&G) $30
T-shirts (polo, ed hardy, lacoste) $14
Jean (True Religion, ed hardy, coogi)$34
Sunglasses ( Oakey, coach, Gucci, Armaini)$15
New era cap $16
Biki ni (Ed hardy, polo) $18
==== ==

Discuss This Question:  

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: