Jump to content

Help needed on "set WshShell = WScript.CreateObject("WScript.Shell")"


Recommended Posts

Posted

We currently are running Windows 7 (32BIT) on the entire network and are now testing as small amount of Windows 10 (64BIT).

 

We currently run the below script to install the Go4Schools link on the desktop at login. This works fine for our Windows 7 (32BIT) but on Windows 10 as the program is 32BIT its installed into a Program Files (x86) by default and the location cannot be changed. Obviously for the time being we still need to use the below script but need additional script "if""else" that if the below isn't on the local computer to create the alternative path on the links.

 

set WshShell = WScript.CreateObject("WScript.Shell")

strDesktop=WshShell.SpecialFolders("Desktop")

set oShellLink=WshShell.CreateShortcut(strDesktop & "\Go4Schools.lnk")

oShellLink.TargetPath="C:\Program Files\Hyperspheric Solutions Ltd\GO Login Tool v2\Go.Login.exe"

oShellLink.WindowStyle = 1

oShellLink.IconLocation = "\\server_name\apps\Group Policies\go.ico, 0"

oShellLink.Description = "Go4Schools"

oShellLink.WorkingDirectory = "C:\Program Files\Hyperspheric Solutions Ltd\GO Login Tool v2"

oShellLink.Save

 

Any pointers would be very much appreciated.

Thank you in advance.

Posted (edited)

$OSVer = [environment]::OSVersion.Version

if ($OSVer.Major -like "10") {

$WShell = New-Object -ComObject ("WScript.Shell")

$ShortCut = $WShell.CreateShortcut($env:USERPROFILE + "\Desktop\Lync.lnk")

$ShortCut.TargetPath = "C:\Program Files\Microsoft Office\Office16\Lync.EXE"

$ShortCut.WorkingDirectory = "C:\Program Files\Microsoft Office\Office16"

$ShortCut.WindowStyle = 1

$ShortCut.IconLocation = "C:\Program Files\Microsoft Office\Office16\Lync.ico, 0"

$ShortCut.Description = "Office Lync 2016"

$ShortCut.Save()

}

elseif ($OSver.Major -like "6*") {

$WShell = New-Object -ComObject ("WScript.Shell")

$ShortCut = $WShell.CreateShortcut($env:USERPROFILE + "\Desktop\Lync.lnk")

$ShortCut.TargetPath = "C:\Program Files (x86)\Microsoft Office\Office16\Lync.EXE"

$ShortCut.WorkingDirectory = "C:\Program Files (x86)\Microsoft Office\Office16"

$ShortCut.WindowStyle = 1

$ShortCut.IconLocation = "C:\Program Files (x86)\Microsoft Office\Office16\Lync.ico, 0"

$ShortCut.Description = "Office Lync 2016"

$ShortCut.Save()

}

If I where doing it in PowerShell it would look a little like that, although you could just use a security filter on a GPO and just apply the GPO to the right set of work stations, If you see what I am saying. You could use gp prefs to create the short cut and dispense of the scripts all together. Anyhow that's a few options to consider.

Edited by HPlum78
Posted
We currently are running Windows 7 (32BIT) on the entire network and are now testing as small amount of Windows 10 (64BIT).

 

We currently run the below script to install the Go4Schools link on the desktop at login. This works fine for our Windows 7 (32BIT) but on Windows 10 as the program is 32BIT its installed into a Program Files (x86) by default and the location cannot be changed. Obviously for the time being we still need to use the below script but need additional script "if""else" that if the below isn't on the local computer to create the alternative path on the links

Any pointers would be very much appreciated.

 

You kinda partially answered your own question by quoting the path "Program Files (x86)".

 

So based on that you could run a check to see if the main EXE exists in a specific path using the environment variables below:

 

Set wshShell = CreateObject("WScript.Shell")

 

pfiles = wshShell.ExpandEnvironmentStrings("%PROGRAMFILES%")

 

pfiles86 = wshShell.ExpandEnvironmentStrings("%PROGRAMFILES(x86)%")

 

 

So you in essence you would say:

 

Set wshShell = CreateObject("WScript.Shell")

 

pfiles = wshShell.ExpandEnvironmentStrings("%PROGRAMFILES%")

 

pfiles86 = wshShell.ExpandEnvironmentStrings("%PROGRAMFILES(x86)%")

 

Set fso = CreateObject("Scripting.FileSystemObject")

 

If fso.FileExists(pfiles & "\Hyperspheric Solutions Ltd\GO Login Tool v2\Go.Login.exe"") Then

'Do Something

ElseIf fso.FileExists(pfiles86 & "\Hyperspheric Solutions Ltd\GO Login Tool v2\Go.Login.exe"") Then

'Do Something

End If

Posted

You kinda partially answered your own question by quoting the path "Program Files (x86)".

 

So based on that you could run a check to see if the main EXE exists in a specific path using the environment variables below:

 

Set wshShell = CreateObject("WScript.Shell")

 

pfiles = wshShell.ExpandEnvironmentStrings("%PROGRAMFILES%")

 

pfiles86 = wshShell.ExpandEnvironmentStrings("%PROGRAMFILES(x86)%")

 

 

So you in essence you would say:

Set wshShell = CreateObject("WScript.Shell")

pfiles = wshShell.ExpandEnvironmentStrings("%PROGRAMFILES%")

pfiles86 = wshShell.ExpandEnvironmentStrings("%PROGRAMFILES(x86)%")

Set fso = CreateObject("Scripting.FileSystemObject")

If fso.FileExists(pfiles & "\Hyperspheric Solutions Ltd\GO Login Tool v2\Go.Login.exe"") Then
'Do Something
ElseIf fso.FileExists(pfiles86 & "\Hyperspheric Solutions Ltd\GO Login Tool v2\Go.Login.exe"") Then
'Do Something
End If

Posted (edited)

Here is my final example using Google Chrome

 

set WshShell = WScript.CreateObject("WScript.Shell")

strDesktop=WshShell.SpecialFolders("Desktop")

set oShellLink=WshShell.CreateShortcut(strDesktop & "\Google Chrome.lnk")

pfiles = wshShell.ExpandEnvironmentStrings("%PROGRAMFILES%" )

pfiles86 = wshShell.ExpandEnvironmentStrings("%PROGRAMFILES(x86)%")

Set fso = CreateObject("Scripting.FileSystemObject")

If fso.FileExists(pfiles & "\Google\Chrome\Application\chrome.exe") Then

oShellLink.TargetPath = pfiles & "\Google\Chrome\Application\chrome.exe"
oShellLink.WindowStyle = 1
oShellLink.IconLocation = pfiles & "\Google\Chrome\Application\chrome.exe, 0"
oShellLink.Description = "Google Chrome"
oShellLink.WorkingDirectory = pfiles & "\Google\Chrome\Application"
oShellLink.Save

ElseIf fso.FileExists(pfiles86 & "\Google\Chrome\Application\chrome.exe") Then

oShellLink.TargetPath = pfiles86 & "\Google\Chrome\Application\chrome.exe"
oShellLink.WindowStyle = 1
oShellLink.IconLocation = pfiles86 & "\Google\Chrome\Application\chrome.exe, 0"
oShellLink.Description = "Google Chrome"
oShellLink.WorkingDirectory = pfiles86 & "\Google\Chrome\Application"
oShellLink.Save

End If

Edited by ass17

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...