|
-
Jan 31st, 2012, 05:10 PM
#1
Thread Starter
Lively Member
VB script to create windows share and mapped drive
I have a script that works perfect for mapping a drive X: to a share that is always created. I want to use %computername% but it won't accept it. My goal is to have a logon script and I am mapping back to the local computer. So I want to create a share %computername%\%temp% and then map x: to that share. Here is what I have so far that works if I hard code a windows box name in. I need help getting the code for the creation of the share as well.
Code:
'==========================================================================
' NAME: NetworkMap.vbs
'
' AUTHOR: Jason Poth
' DATE : 1/27/2012
'
' COMMENT:
' This script maps X drive to "\\Server\Share" and then launch Program
'==========================================================================
Dim objFSO, objNetwork, WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("WScript.Network")
'-----------------------------------------------------------------
'If the "x" drive is already mapped, disconnect the mapping
If (objFSO.DriveExists("x:")) Then
objNetwork.RemoveNetworkDrive "x:", True, True
End If
'-----------------------------------------------------------------
objNetwork.MapNetworkDrive "x:" , "\\win7dev\temp"
If Err.Number<>0 Then
MsgBox "Error in mapping drive!!!!"
MsgBox "Error #" & Err.Number & " " & Err.Description
End If
'-----------------------------------------------------------------
'Execute Program
'-----------------------------------------------------------------
WshShell.Run "P:\program.exe%"
If Err.Number<>0 Then
MsgBox "Unable to launch program !"
MsgBox "Error #" & Err.Number & " " & Err.Source & " " & Err.Description
End If
set WshShell = Nothing
-
Feb 1st, 2012, 10:04 AM
#2
Thread Starter
Lively Member
Re: VB script to create windows share and mapped drive
-
Feb 1st, 2012, 04:08 PM
#3
Re: VB script to create windows share and mapped drive
Post the code lines you want to use that don't work. Have you checked to see what the contents of the %computername% environment variable are?
-
Feb 1st, 2012, 04:29 PM
#4
Thread Starter
Lively Member
Re: VB script to create windows share and mapped drive
I found a script in powershell that does the job but then wscript can't call a ps1 file which I need it to do. The script above works as for mapping a drive and calling the program, but I need it to create a share in %username%\temp and then map the x: drive based off that share. My script above will map x: if I hard code the share path. I need to use a variable.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|