Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

VBScript Elevated Permissions problem.

$
0
0

     I've found just about every posting related to Elevated permissions with VBScript.  I've been using one I found 5 years ago and it has worked like a charm up until recently.  My scripting has gotten better but I'm still fairly wet behind the ears.  I've added things to my scripts like write to a file, detect current directory, scripted folder detection and a few others.  When I usually run my scripts it saves the file in the current folder.  The company I work for does something funky to their computers.  When I run my scripts it will either save the text output in C: root or C:\Windows\System32.

     The first problem I resolved by adding the detect folder (strCurrentFolder & "\Data").  Then the problem was if I run my script from the network location, mapped or unmapped it runs fine.  If I run it as the end user it gives an error, but not a permissions error.  I changed the objShell to admShell (my own name) so it does not conflict with the objShell that executes installs.  At first that resolved the problem for everyone but then it started to fail so I had to give everyone full Read\Write permissions on the folder.  Now it runs fine until recently.  Now if I run it no matter who it is, including me it says "Cannot find Script File" and it gives the name of the script and the location where it is.  No matter where I move the VBScript file it finds it and says it cannot find the file and gives the exact path including the correct name.  Needless to say I'm pulling my hair out trying to find this.  I am also getting tired of hearing people tell me "You should try PowerShell".  I'm sorry but I love VBScript, I like the control I have.  I do not want to open a program to run my scripts.  I want them to double click and go.  My "One Click Fixes" have been fool proof, even the end users can run them without knowing a thing about computers.

     Now that my ranting and history is over, I have a question.  Can you tell me what is the problem with our company computers that they have this flaky problem?  I'm sure it's something in the registry or an environmental variable like the path.  I may be able to resolve the problem by making Subs or Functions but for the most part they've been running fine as one big community of code :)  I'm about to do that but before I did I wanted someone to either answer the first question about why this companies computers are the only ones that do this? or Tell me what the best way to run a script in elevated permissions that I can install software with? and\or Is there a problem with my code (besides it being one big script, instead of subs)?

FYI: I like being prepared for the unexpected so I have a lot of things in my scripts that I may not use in each script.  This particular script I modify to do different things related to installing software and creating shortcuts.  If any of these are causing the problem that might be the case but this script works fine without the elevated permissions when I run it on Windows XP.  The only error I get is with the elevated permissions part of the script.

I will post on every forum, facebook and twitter too that you are the greatest and nicest programmer in the world if you can resolve this problem.  I'm not rich, I have no savings and no retirement other than Social "In" Security.  But I will give you my loyalty for life. :)

' =============== START ADMIN RIGHTS ===============
' This adds the Admin Run Function for Windows Vista and 7
' You must put this at the top below computer and End If at the
' very end of the script

Dim admShell
If WScript.Arguments.length = 0 Then
Set admShell = CreateObject("Shell.Application")
admShell.ShellExecute "WScript.exe", """" & _
WScript.ScriptFullName & """" &_
" RunAsAdministrator", , "runas", 1
Else

' =============== END ADMIN RIGHTS ===============

' On Error Resume Next

Dim objFSO, objNet, objShell, objShortcutUrl
Dim colEnvironmentVariables, ShellLink, WshShell
Dim strAllUsersStartMenu, strAllUsersPrograms, strWindowsDir
Dim strComputer, strQuickLaunch, strProgramFilesDir
Dim strDesktopPath, strDocuments, strFavoritesPath
Dim strCurrentDirectory

strComputer = "."

' ==============================================================================
' Create System Objects
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNet = CreateObject("WScript.Network")
Set objShell = CreateObject("WScript.Shell")
Set WshShell = WScript.CreateObject("WScript.Shell")
Set colEnvironmentVariables = objShell.Environment("Volatile")
' ==============================================================================

' objShell
strDesktopPath = objShell.SpecialFolders("Desktop")
strFavoritesPath = objShell.SpecialFolders("Favorites")
strAllUsersStartMenu = objShell.SpecialFolders("AllUsersStartMenu")
strAllUsersPrograms = objShell.SpecialFolders("AllUsersPrograms")
strDocuments = objShell.SpecialFolders("MyDocuments")

' colEnvironmentalVariables
strQuickLaunch = colEnvironmentVariables.Item("APPDATA") _
 & "\Microsoft\Internet Explorer\Quick Launch\"

' objShell Expand
strWindowsDir = objShell.ExpandEnvironmentStrings("%windir%")
strProgramFilesDir = objShell.ExpandEnvironmentStrings("%programfiles%")

' Opens File System Object for creating text file
strCurrentDirectory = objFSO.GetParentFolderName(Wscript.ScriptFullName)

' STEP: 1 frminst.exe –forceuninstall
objShell.Run (strProgramFilesDir & "\McAfee\Common Framework\frminst.exe" & " –forceuninstall"), ,True

' STEP: 2 is informational only.
' Download programs to your local computer to save time.

' STEP: 3a run Americas1MA_WIN_461_FramePkg.exe
objShell.Run "Q:\IT\McAfeeAVInstall\Americas1.MA_WIN_461_FramePkg.exe", , True

' STEP: 3b
objShell.Run (strProgramFilesDir & "\McAfee\Common Framework\CmdAgent.exe /P"), , True
objShell.Run (strProgramFilesDir & "\McAfee\Common Framework\CmdAgent.exe /E"), , True
objShell.Run (strProgramFilesDir & "\McAfee\Common Framework\CmdAgent.exe /C"), , True

' STEP: 3c run McAfee_AVDefinition.exe
objShell.Run ("Q:\IT\McAfeeAVInstall\McAfee_AVDefinition_1.0_V01.EXE"), , True

' STEP: 3d run McAfee_VirusScanEnterprisePackage_8.8_V01.EXE
objShell.Run ("Q:\IT\McAfeeAVInstall\McAfee_VirusScanEnterprisePackage_8.8_V01.EXE"), , True

' Ending Message
MsgBox"McAfee Update - Sophos Removal" & VbCrLf & _
 "Has Been Completed", ,"Click OK To Close"

' Cleans Memory
Set objFSO = Nothing
Set objNet = Nothing
Set objShell = Nothing
Set objShortcutUrl = Nothing
Set colEnvironmentVariables = Nothing
Set ShellLink = Nothing
Set WshShell = Nothing
Set strAllUsersStartMenu = Nothing
Set strAllUsersPrograms = Nothing
Set strComputer = Nothing
Set strQuickLaunch = Nothing
Set strProgramFilesDir = Nothing
Set strWindowsDir = Nothing
Set strDesktopPath = Nothing
Set strDocuments = Nothing
Set strFavoritesPath = Nothing
Set strCurrentDirectory = Nothing

End If


Helpful nice guy


Viewing all articles
Browse latest Browse all 15028

Trending Articles