/build/static/layout/Breadcrumb_cap_w.png

Vbscript, Windows 7 and C:\ProgramData\Microsoft\Windows\Start menu\Programs

In the process of migrating scripts from our Altiris servers to the Kace K1000 server and I am running into an issue. I am unable to successfully run the below script on a Windows 7 client via Kace. I am sure it is a setting I am missing, but it is in the C:\ProgramData\Microsoft\Windows\Start menu\Programs folder which is non writeable to non-admins.

I have set the Run As command as Local user as well as my user who does have local admin rights on the client machine. The vbscript (Intervals - Shortcut.vbs) was uploaded as a dependency and the On Success job steps are below. No other steps created for script.

The script is failing on the CreateFolder line in the vbscript due to permissions.

Directory: $(KACE_SYS_DIR)
File: cscript.exe
Parameters: (KACE_DEPENDENCY_DIR)\Intervals - Shortcut.vbs

Vbscript Below

' Create Directory
Dim fs,f
Set fs=CreateObject("Scripting.FileSystemObject")
set f=fs.CreateFolder("C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Intervals")

' Create Shortcut
Dim oShell : Set oShell = WScript.Createobject("WScript.Shell")
Dim oNetwork : Set oNetwork = CreateObject("WScript.Network")
Dim sAllUsersProfile : sAllUsersProfile = oShell.ExpandEnvironmentStrings("%AllUsersProfile%")
Set oShellLink = oShell.CreateShortcut(sAllUsersProfile & "\Microsoft\Windows\Start menu\Programs\Intervals\Intervals - Timesheet.url")
oShellLink.TargetPath = https://REMOVED_TO_PROTECT_THE_INNOCENT
oShellLink.Save


0 Comments   [ + ] Show comments

Answers (4)

Answer Summary:
Posted by: jagadeish 11 years ago
Red Belt
1

I didn't get any error if the script is executed as local admin...

One suggestion here

Since you have not used the below object anywhere, you can remove them from the above code

Dim oNetwork : Set oNetwork = CreateObject("WScript.Network")

Your URL should be given with in ""

oShellLink.TargetPath = "https://REMOVED_TO_PROTECT_THE_INNOCENT"


Comments:
  • You have already variablized ALLUSERPROFILE

    Dim sAllUsersProfile : sAllUsersProfile = oShell.ExpandEnvironmentStrings("%AllUsersProfile%")

    But you have not used it in CreateFolder section.. - jagadeish 11 years ago
  • jagadeish, the qoutes were removed when I posted code into the new post window. I have the qoutes in the original script.

    The create folder code creates the folder in the Start Menu location that will be used for the shortcut code to point to the new created folder. I had a previous built script that worked with the AllUsersProfile special folder, but it did not work on Kace, so I hobbled together this version. Thanks for your help. - SecurityTeam 11 years ago
  • Did you try this?
    http://www.itninja.com/blog/view/kace-running-vbs-script-in-scripting - jagadeish 11 years ago
Posted by: jagadeish 11 years ago
Red Belt
1

Can you try this one as local admin..

Option Explicit

Dim oShell, objFSO, sAllUsersProfile
Dim oShellLink
Dim TargetLocation, TargetURL

Set oShell = WScript.Createobject("WScript.Shell")
Set objFSO=CreateObject("Scripting.FileSystemObject")
sAllUsersProfile = oShell.ExpandEnvironmentStrings("%AllUsersProfile%")

TargetLocation = sAllUsersProfile & "\Microsoft\Windows\Start Menu\Programs\Intervals"
TargetURL="https://www.google.com"

If Not objFSO.FolderExists(TargetLocation) Then
objFSO.CreateFolder(TargetLocation)
End If

Set oShellLink = oShell.CreateShortcut(TargetLocation & "\Intervals - Timesheet.url")
oShellLink.TargetPath = TargetURL
oShellLink.Save

 

Set oShellLink = Nothing
Set oShell = Nothing
Set objFSO = Nothing

WScript.Quit


Comments:
  • jagadeish, this script did not work either. Do you know how to get the output of the script to be written to the jobs scripting log? - SecurityTeam 11 years ago
  • Did you try this?
    http://www.itninja.com/blog/view/kace-running-vbs-script-in-scripting - jagadeish 11 years ago
  • that is how I have the job setup.
    I know the issue is due to the folder creation in the restricted directory. I have quite a few other scripts that do make changes in restricted directories.
    Thanks for your help. - SecurityTeam 11 years ago
  • I think the issue is the account you are using to execute this VBScript.. As a Local Admin, I'm able to execute this script in Windows 7 machine..and the shortcut is getting created as expected.. - jagadeish 11 years ago
    • When I run as local admin on machine I have to do the UAC and it works, everything works, folder created and shortcut created. I am using an account that is in the local admin group in Kace, and it does not work, no folder created and shortcut not created. - SecurityTeam 11 years ago
  • you are running as local admin on the machine or using the local admin credentials in Kace? - SecurityTeam 11 years ago
    • Using the local admin credentials in Kace will not work. It will need to be machine credentials. - dugullett 11 years ago
  • Found out the resolution to the issue. It was due to the vbscript file name having a space in the name. Called into support and after enabling client side logging we saw that in the logs. Issue is now resolved. Thanks for all suggestions. - SecurityTeam 11 years ago
Posted by: dugullett 11 years ago
Red Belt
0

Add this to the top of your script. Then set run as in Kace to SYSTEM to bypass the UAC.

If WScript.Arguments.Named.Exists("elevated") = False Then

'Launch the script again as administrator

CreateObject("Shell.Application").ShellExecute "wscript.exe", """" & WScript.ScriptFullName & """ /elevated", "", "runas", 1

WScript.Quit

Else

'Change the working directory from the system32 folder back to the script's folder.

Set oShell = CreateObject("WScript.Shell")

oShell.CurrentDirectory = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName)

End If
Posted by: SecurityTeam 11 years ago
Senior White Belt
0

Found out the resolution to the issue. It was due to the vbscript file name having a space in the name. Called into support and after enabling client side logging we saw that in the logs. Issue is now resolved. Thanks for all suggestions.

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ