Escaping special characters in run with administrator privileges script

5 pts.
Tags:
VB
VB script
Hello, reviving an old one on this forum: http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/special-characters-in-vbscript-strings/
I used this script:
Here is a VB Script Vall Script that will get around the Password Prompt when "RunAs" is called...

'Start

'-----------------------------------------------------------------------------------

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

'----------------------------------------------------------------------------------

Dim WshShell, objFSO

suser = "YourAdminAccount@YourDomain.com"

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 @YourDomain.com

'-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

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)

WScript.quit

'End

 

Now my problem: my users account name is:

"user's"

 

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



SOURCE: http://community.spiceworks.com/scripts/show/1078-cleanup-start-menu-items



Thank you in advance...



And Peace!



Devvie



[[User:Devnullius|Devnullius]] notemail@facebook.com [[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)





PS: http://www.asciitable.com/ 





Software/Hardware used:
vista x86
ASKED: May 1, 2012  8:32 PM
UPDATED: May 3, 2012  12:40 PM

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 ==== http://www.fashion-long-4biz.com ==
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
FREE SHIPPING
==== http://www.fashion-long-4biz.com ==

http://www.fashion-long-4biz.com

http://www.fashion-long-4biz.com

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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

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

Following