Pages

Tuesday 19 June 2012

Set Shortcut Working Directory - VBScript

Following script checks for Windows XP or Windows7 and sets working directory accodingly.


'Option Explicit


Dim objShell, ALLUSERSPROFILE, SysDrive, objShtCut


Set objShell = WScript.CreateObject("WScript.Shell")
ALLUSERSPROFILE =objShell.ExpandEnvironmentStrings("%ALLUSERSPROFILE%")
APPDATA =objShell.ExpandEnvironmentStrings("%APPDATA%")




strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")


Set colOperatingSystems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")


For Each objOperatingSystem in colOperatingSystems
    ver= objOperatingSystem.Caption 
Next


S = InStr(ver,"XP")




If S > 0 Then


Set objShtCut = objShell.Createshortcut(ALLUSERSPROFILE &"\Start Menu\Programs\SampleTest.lnk")
objShtCut.WorkingDirectory = APPDATA & "\Sample"

objShtCut.Save


else


Set objShtCut = objShell.Createshortcut(ALLUSERSPROFILE &"\Microsoft\Windows\Start Menu\Programs\SampleTest.lnk")
objShtCut.WorkingDirectory = APPDATA & "\Sample"
objShtCut.Save


end if
WScript.Quit

No comments:

Post a Comment