Jump to content











Photo
- - - - -

Auto-mapping network drives


  • Please log in to reply
11 replies to this topic

#1 BRow86

BRow86

    Newbie

  • Members
  • 13 posts
  • Location:Boston, MA
  • Interests:Rugby, computing, cars, gaming, music, etc.
  •  
    United States

Posted 30 March 2008 - 03:21 AM

Hello all,

I am getting back into building my PE mostly because I want to convince the people I work for to drop BartPE cause, honestly, I feel it's too damn clunky. One thing I want to do is try and make a script to auto-map network drives. I did some google work and came up with some code (I know little to no VB code)
Here's what I found:

Option Explicit
Dim objNetwork
Dim strDriveLetter, strRemotePath, strUser, strPassword, strProfile

' Values of variables set
strDriveLetter = "H:"
strRemotePath = "\\alan\home"
strUser = "guytom"
strPassword = "£@ssw0rd1"
strProfile = "false"

Set objNetwork = WScript.CreateObject("WScript.Network")
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, _
strProfile, strUser, strPassword

' Extra code just to add a message box
WScript.Echo " Launch Explorer, check: "& strDriveLetter
WScript.Quit



I need a little help implementing this. First off, does anyone have any idea what "strProfile" relates to? Also, and I'm totally guessing here cause I = VB noob, but I don't need the whole "WScript" up there since I can run this under the [Process] in the script, right? What would be REALLY cool is if I (or someone who feels motivated...) could eventually come up with an interface such that the username/password could be provided within Winbuilder along with a dropdown of a number of drives to be mapped. I'll try it later this week with any luck/if I find time away from my classes. Thanks for any help.

#2 MichaelZ

MichaelZ

    Frequent Member

  • Team Reboot
  • 333 posts
  • Location:Braunschweig, Germany
  •  
    Germany

Posted 30 March 2008 - 07:16 AM

First off, does anyone have any idea what "strProfile" relates to?

In MSDN Library I have looked up the MapNetworkDrive method. That parameter is a boolean (thanks to auto-casting it can also be passed as a string) and if set true, the mapping information is stored in the users profile.

bUpdateProfile
Optional. Boolean value indicating whether the mapping information is stored in the current user's profile. If bUpdateProfile is supplied and has a value of true, the mapping is stored in the user profile (the default is false).



PS- I'm throwing in my Ghost8 and script for anyone interested (Put it in apps/disc tools). There was one I had before floating around but this one is much better.

I was also a long time user of Ghost 8. But now I use more often Drive Snapshot (script also available in this forum). I think it has two advantages. One can make a disc image from the system partition not only when another system (e.g. VistaPE) is booted but also from the running system (and one doesn't have to install such huge things as Ghost 14). The second advantage is the ability to mount the backup as a drive, this is much faster that than to open the backup using Ghost Explorer and wait hours until it is loaded.

Many Greetings
MichaelZ

#3 BRow86

BRow86

    Newbie

  • Members
  • 13 posts
  • Location:Boston, MA
  • Interests:Rugby, computing, cars, gaming, music, etc.
  •  
    United States

Posted 30 March 2008 - 04:06 PM

In MSDN Library I have looked up the MapNetworkDrive method. That parameter is a boolean (thanks to auto-casting it can also be passed as a string) and if set true, the mapping information is stored in the users profile.


Alright, so if I assume each VistaPE I build could be for someone different, does that means it can ignore this variable? Thanks for the help and advice about drive snapshot. I'll grab that and throw it into my PE.

#4 MichaelZ

MichaelZ

    Frequent Member

  • Team Reboot
  • 333 posts
  • Location:Braunschweig, Germany
  •  
    Germany

Posted 30 March 2008 - 05:44 PM

does that means it can ignore this variable?

I would say yes. After next boot of VistaPE that profile will not have survived anyhow. :thumbsup:

Many Greetings
MichaelZ

#5 JonF

JonF

    Gold Member

  • .script developer
  • 1185 posts
  • Location:Boston, MA
  •  
    United States

Posted 30 March 2008 - 08:02 PM

Seems as if VBscript is a little overkill. How about a CMD file:

net use H: \\alan\home  /user:guytom "£@ssw0rd1" /persistent:no

You might need to replace "guytom" with "domain\guytom" (replacing "domain" with your domain name).

#6 BRow86

BRow86

    Newbie

  • Members
  • 13 posts
  • Location:Boston, MA
  • Interests:Rugby, computing, cars, gaming, music, etc.
  •  
    United States

Posted 03 April 2008 - 12:24 AM

Seems as if VBscript is a little overkill. How about a CMD file:

net use H: \\alan\home  /user:guytom "£@ssw0rd1" /persistent:no

You might need to replace "guytom" with "domain\guytom" (replacing "domain" with your domain name).



Jon-- very, very nice. That is a really great shortcut. For the first version I will hard-code the values but for the future I wanted to make an interface but anyhow. How would I go about throwing this into a .script? More specifically, how do you run that command from the .script file? Also, for future reference, is there a way from the interface to import user-entered strings (I'm thinking for domain/username /password)? Thanks again.

#7 allanf

allanf

    Gold Member

  • .script developer
  • 1256 posts

Posted 03 April 2008 - 06:54 AM

Jon-- very, very nice. That is a really great shortcut. For the first version I will hard-code the values but for the future I wanted to make an interface but anyhow. How would I go about throwing this into a .script? More specifically, how do you run that command from the .script file? Also, for future reference, is there a way from the interface to import user-entered strings (I'm thinking for domain/username /password)? Thanks again.


Hi BRow86,

I hate to be a party-pooper, but I'm fairly certain that you cannot throw away free copies of Ghost 8 - if that is what is encoded in the attachment to your first post.

A Winbuilder .script for the Command file might contain the following elements:

[Interface] Section with Interface Variables, such as 'pTextBox1', 'pTextBox2', etc for user input.

[Process] Section with:

1. 'FileCreateBlank,...' to create the .cmd file somewhere in VistaPE's Target Directory.

2. 'TxtAddLine,...' to append the 'Net Use <%InterfaceVariable%> <%InterfaceVariable%> ...' line to to the .cmd.

3. An AutoStart API Command to make VistaPE run the .cmd file when VistaPE boots. Or a Shortcut API Command for the user to start the .cmd file in VistaPE.

Doing it this way, I think you would need to be certain that the parameters specified in the Interface Variables when you build VistaPE are appropriate for every machine on which you boot the VistaPE build. For example, Will the same drive letter always be available? The path to the share, etc?

A third alternative to VBScript and .cmd is an HTA. Currently I'm looking at one from MS's Hey, Scripting Guy which is not setup to take user-names and passwords, but does find available Drive Letters. You would need to copy the HTA script from the WebSite and save as .hta. In a Winbuilder .script, instruct Winbuilder to copy the .hta to VistaPE's Target Directory. Then, from booted VistaPE, run it from the Command-line using 'mshtm.exe', assuming VistaPE supports HTAs.... a little complicated to create AutoStart or Shortcuts, but certainly not impossible. EDIT: Also requires support for WMI and XML.

Sorry that this is a just a vague outline. If you need more help, I'm sure the community will be glad to assit. You have come up with a very good idea!

Regards :thumbsup:

#8 JonF

JonF

    Gold Member

  • .script developer
  • 1185 posts
  • Location:Boston, MA
  •  
    United States

Posted 03 April 2008 - 04:05 PM

Jon-- very, very nice. That is a really great shortcut. For the first version I will hard-code the values but for the future I wanted to make an interface but anyhow. How would I go about throwing this into a .script? More specifically, how do you run that command from the .script file? Also, for future reference, is there a way from the interface to import user-entered strings (I'm thinking for domain/username /password)? Thanks again.

Do you want to enter the domain/user/password when you build the VistaPE ISO or when you run the command or both? Do you want the command to autorun at boot time or be activated by a shortcut? or both? All sorts of things can be done ...

#9 BRow86

BRow86

    Newbie

  • Members
  • 13 posts
  • Location:Boston, MA
  • Interests:Rugby, computing, cars, gaming, music, etc.
  •  
    United States

Posted 04 April 2008 - 07:38 PM

Do you want to enter the domain/user/password when you build the VistaPE ISO or when you run the command or both? Do you want the command to autorun at boot time or be activated by a shortcut? or both? All sorts of things can be done ...



I wanted to have the domain/user/password all filled before the build process. For later maybe I could make a program to put into the PE to make it easier for people to map drives. But anyway, for now I was going to do it through the interface.

#10 JonF

JonF

    Gold Member

  • .script developer
  • 1185 posts
  • Location:Boston, MA
  •  
    United States

Posted 04 April 2008 - 09:18 PM

It might look something like this (untested):

&#91;Main&#93;

Title=Map drive H

Author=Jon Fleming

Level=5

Version=011

Description=

Locked=false

Contact=

Date=04.04.2008

Selected=True



&#91;Variables&#93;

%ProgramFolder%=MapDriveH

%ProgramEXE%=MapDriveH.cmd

%ProgramTitle%=Map Drive H



&#91;Process&#93;

Echo,Processing %ProgramTitle%...

RunFromRam,%pCheckBox1%

Unpack,MapDriveH

Add_Shortcut,StartMenu,Network,&#34;%PE_Programs%\%ProgramFolder%\%ProgramEXE%&#34;,&#34;%ProgramTitle%&#34;,&#34;%PE_Programs%\%ProgramFolder%&#34;,&#34;%pTextBox1% %pTextBox2% %pTextBox3% %pTextBox4%&#34;

If,%pCheckBox2%,Equal,true,Add_Shortcut,Desktop,,&#34;%PE_Programs%\%ProgramFolder%\%ProgramEXE%&#34;,&#34;%ProgramTitle%&#34;,&#34;%PE_Programs%\%ProgramFolder%&#34;,&#34;%pTextBox1% %pTextBox2% %pTextBox3% %pTextBox4%&#34;



&#91;EncodedFolders&#93;

MapDriveH



&#91;EncodedFile-MapDriveH-MapDriveH.cmd&#93;

lines=0

0=eJxdjjsKwzAQRHuD7zAYVBt/KkEgpZtADpBmidbYBEuLJCfXzyrp1C3z3rBz5ecWENa1bdrGWtxI4OL+ZizIAQTP+RPi6x/+lDtFOjhzxGAhlLciHiTCDmmjWFsjLnDhoN1XYFJwJj28BhWblQmlpL9dmaYziovFwgxAX3rWjA8zoTN

zh144pj1l9tn60DZCanwBqr9D63ic4/VNLHApyixL9dBLzk1hGAUjDNyF0tNxyO9kWzWBgQkAcX4IP6j3bgQBAAAAAgAAACcAAACXAAAAAAAAAA

EAAAAAAAAAAAAAAA



&#91;MapDriveH&#93;

MapDriveH.cmd=226bytes,302bytes



&#91;Interface&#93;

pTextLabel1=&#34;Network Share&#58;&#34;,1,1,10,38,77,18,8,Normal

pTextLabel2=Domain&#58;,1,1,44,82,42,20,8,Normal

pTextLabel3=&#34;User name&#58;&#34;,1,1,27,107,57,18,8,Normal

pTextLabel4=Password&#58;,1,1,31,130,53,18,8,Normal

pCheckBox1=&#34;Run from RAM &#40;boot.wim&#41;&#34;,1,3,21,213,200,18,False

pTextBox1=,1,0,91,38,200,18,\\alan\home\

pTextBox2=,1,0,89,83,200,18,Me

pTextBox3=,1,0,90,108,200,21,guytom

pTextBox4=pTextBox4,1,0,90,128,200,21,£@ssw0rd1

pCheckBox2=&#34;Add shortcut to desktop&#34;,1,3,20,240,200,18,True

THis version requires the domain; you might want to change "Me" in "pTextBox2=,1,0,89,83,200,18,Me" to the real domain name.

FYI, MapDriveH.cmd looks like:

@echo off



&#58;&#58; Map drive H to a network drive

&#58;&#58; Parameter 1 = path to mapped share

&#58;&#58; Parameter 2 = domain

&#58;&#58; Parameter 3 = user name

&#58;&#58; Parameter 4 = password



net use H&#58; %1  /user&#58;%2\%3 &#34;%4&#34; /persistent&#58;no

pause


#11 JRG

JRG
  • Members
  • 7 posts
  •  
    Denmark

Posted 25 April 2008 - 09:23 AM

Currently I'm looking at one from MS's Hey, Scripting Guy which is not setup to take user-names and passwords, but does find available Drive Letters

If you want to make sure you're not accidentally mapping a network letter already assigned to a local drive use the CMD build-in PUSHD command. PUSHD automatically assigns an available driveletter and does a change directory to this letter.

PUSHD doesn't however take credentials, so you'll have to establish an authenticated conneciton to the share first. Example:

NET USE \\MyServer\MyShare mypassword /user:myusername [establish authenticated connection]
PUSHD \\MyServer\MyShare [map first available driveletter (from Z and down) to share and CD to share]

You'll likely end up with drive Z:.

If you need to know with driveletter you were assigned use the variable %cd% (returns current directory, which is where PUSHD put you).
If you need to remove the driveletter again use POPD (no arguments). This will remove the letter and return you to the driveletter you came from.

I write VBScript (alias WSH) too, and while it's a very flexible language it's way overkill in this situation (as already mentioned).

#12 allanf

allanf

    Gold Member

  • .script developer
  • 1256 posts

Posted 25 April 2008 - 10:15 AM

NET USE \\MyServer\MyShare mypassword /user:myusername [establish authenticated connection]
PUSHD \\MyServer\MyShare [map first available driveletter (from Z and down) to share and CD to share]

You'll likely end up with drive Z:.

If you need to know with driveletter you were assigned use the variable %cd% (returns current directory, which is where PUSHD put you).
If you need to remove the driveletter again use POPD (no arguments). This will remove the letter and return you to the driveletter you came from.


Hi JRG,

Thanks. That's an excellent tip. Efficient!

Regards :lol:




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users