Results 1 to 4 of 4

Thread: VB script to create windows share and mapped drive

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    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

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    Re: VB script to create windows share and mapped drive

    bump. Anyone?

  3. #3
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,526

    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?

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    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 &#37;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
  •  



Click Here to Expand Forum to Full Width