Using UNC Paths to Deploy Apps
From CoolSolutionsWiki
Make UNC paths as portable as drive mappings
You need to use UNC paths in your apps, but you need to point to different servers depending on where the user is. Typically, this will be a different site. Thus, you have a different default gateway. If this script runs and finds a non-0 gateway, it will try to match what your computer has with what's in the case statement. If it finds a match, it will write a reg key that you can use in app objects. If not, it exits.
Code is Written in vbscript and runs on any XP (and most 2000) systems.
The code below needs no changes. Because of the Wiki formatting you may have to retype it (stupid).
'Find the Default gateway to use in determining the proper server source
On Error Resume Next
DefaultGateway = Empty
Dim oDG, oDGs, WMI
- Set WMI = GetObject("winmgmts:\\.\root\cimv2")
- Set oDGs = WMI.ExecQuery _
- ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
- For Each oDG in oDGs;
- If Not IsNull(oDG.DefaultIPGateway) Then
- if not oDG.defaultIPGateway(0) = "0.0.0.0" Then
- DefaultGateway = oDG.DefaultIPGateway(0)
- exit for
- DefaultGateway = oDG.DefaultIPGateway(0)
- end if
- if not oDG.defaultIPGateway(0) = "0.0.0.0" Then
- end if
- If Not IsNull(oDG.DefaultIPGateway) Then
- Next
The Code below needs modified for your default gateway, the server for said site, and the share or volume.
Add Case statements as necessary.
Dim WSHShell
Set WSHShell = WScript.CreateObject("WScript.Shell")
'Depending on the gateway, write the appserver and appvolume
Select Case DefaultGateway
Case "10.1.0.254" 'Example Site 1 default gateway
- WSHShell.RegWrite "HKLM\System\CurrentControlSet\Control\Session Manager\Environment\APPSRV", "FRTFS01", "REG_SZ"
- WSHShell.RegWrite "HKLM\System\CurrentControlSet\Control\Session Manager\Environment\APPVOL", "ZENFILES$", "REG_SZ"
Case "10.2.0.254" 'Example Site 2 default gateway
- WSHShell.RegWrite "HKLM\System\CurrentControlSet\Control\Session Manager\Environment\APPSRV", "ALBANY", "REG_SZ"
- WSHShell.RegWrite "HKLM\System\CurrentControlSet\Control\Session Manager\Environment\APPVOL", "ZENFILES$", "REG_SZ"
- 'Add more case statements as necessary
End Select
Set WSHShell = Nothing
WScript.Quit(0)
Now What?
- Test by running cscript.exe scriptname.vbs (scriptname.vbs is your modified script)
- If the script runs without any errors, check your environment variables (My Computer->Properties->Advanced->Env Variables) and make sure they are updated properly.
- Create an app object that runs always when a user logs in and put this script in the Distribution Scripts area
- Now in future apps, instead of using Z:\ or \\siteserver\apps you can replace %SOURCE_PATH% in Macros with \\%APPSRV%\%APPVOL%
This enables you to use one app object @ multiple sites without drive mappings being necessary.
