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

Answer Summary:
Cancel
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Answers

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"

Answered 09/04/2012 by: jagadeish
Red Belt

  • You have already variablized ALLUSERPROFILE

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

    But you have not used it in CreateFolder section..
  • 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.
  • Did you try this?
    http://www.itninja.com/blog/view/kace-running-vbs-script-in-scripting
Please log in to comment
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

Answered 09/04/2012 by: jagadeish
Red Belt

  • 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?
  • Did you try this?
    http://www.itninja.com/blog/view/kace-running-vbs-script-in-scripting
  • 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.
  • 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..
    • 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.
  • you are running as local admin on the machine or using the local admin credentials in Kace?
    • Using the local admin credentials in Kace will not work. It will need to be machine credentials.
  • 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.
Please log in to comment
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
Answered 09/06/2012 by: dugullett
Red Belt

Please log in to comment
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.

Answered 09/06/2012 by: SecurityTeam
Senior White Belt

Please log in to comment
Answer this question or Comment on this question for clarity