I have written the following VBScript program. It is stored into a
file "map_drive.vbs". It successfully mapped to a network drive
\\server1\data.
Dim WshNetwork
Set WshNetwork = WScript.CreateObject("WScript.Network")
sPwd = inputbox("Enter password")
WshNetwork.MapNetworkDrive "J:", "\\server1\data", false,
"xyz_net\John", sPwd
Msgbox "Drives has been map successful"
Could anyone teach me how to convert it to a Visual Basic program such
that it can be compiled to an .exe file?
I tried to use Active X Control – Windows Script Control 1.0. But I
couldn't make it work. Perhaps, I do not know how to use the Script
Control, or it is a totally wrong approach. It will be nice if you can
give Step-by-step instructions.
Please help. Thanks a lot. 8 50317
No idea for the wscript object, but I can give you the API code for VB to
map/unmap drives and a whack of others .. http://vbnet.mvps.org/code/network/netconnect.htm
--
Randy Birch
MVP Visual Basic http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.
"Alex Ang" <Al*******@yahoo.com.sg> wrote in message
news:13**************************@posting.google.c om...
: I have written the following VBScript program. It is stored into a
: file "map_drive.vbs". It successfully mapped to a network drive
: \\server1\data.
:
: Dim WshNetwork
: Set WshNetwork = WScript.CreateObject("WScript.Network")
: sPwd = inputbox("Enter password")
: WshNetwork.MapNetworkDrive "J:", "\\server1\data", false,
: "xyz_net\John", sPwd
: Msgbox "Drives has been map successful"
:
: Could anyone teach me how to convert it to a Visual Basic program such
: that it can be compiled to an .exe file?
: I tried to use Active X Control Windows Script Control 1.0. But I
: couldn't make it work. Perhaps, I do not know how to use the Script
: Control, or it is a totally wrong approach. It will be nice if you can
: give Step-by-step instructions.
: Please help. Thanks a lot.
Alex, it very similar to the vbscript you have already,
Dim WshNetwork ' COULD SET AS TYPE: OBJECT otherwise its a variant
Set WshNetwork = CreateObject("WScript.Network") ' THIS LINE DIFFERS
SLIGHTLY: Note the CreateObject
msgbox("Enter password")
WshNetwork.MapNetworkDrive "J:", "\\server1\data", False, "xyz_net\John",
sPwd
MsgBox "Drives has been map successful"
Set WshNetwork = Nothing ' BEST TO RELEASE THE OBJECT (FREE UP RESOURSES)
hope it helps
al.
"Alex Ang" <Al*******@yahoo.com.sg> wrote in message
news:13**************************@posting.google.c om... I have written the following VBScript program. It is stored into a file "map_drive.vbs". It successfully mapped to a network drive \\server1\data.
Dim WshNetwork Set WshNetwork = WScript.CreateObject("WScript.Network") sPwd = inputbox("Enter password") WshNetwork.MapNetworkDrive "J:", "\\server1\data", false, "xyz_net\John", sPwd Msgbox "Drives has been map successful"
Could anyone teach me how to convert it to a Visual Basic program such that it can be compiled to an .exe file? I tried to use Active X Control - Windows Script Control 1.0. But I couldn't make it work. Perhaps, I do not know how to use the Script Control, or it is a totally wrong approach. It will be nice if you can give Step-by-step instructions. Please help. Thanks a lot.
Thanks Alan, my program can run now. :)
Thanks Randy for your suggestion too.
I have another question regarding Dim. Why can't I do the following.
Dim WshNetwork As WScript.Network
‘Compile Error: User Defined Type Not Define
However the following is all right.
Dim WshNetwork As Object ‘NO error.
Set WshNetwork = CreateObject("WScript.Network")
I was trying the above because I did something similar that make use
of "Excel" object. The VB code is as follows:
Dim XLObj As Excel.Application
Set XLObj = CreateObject("Excel.Application")
To make the above VB code run without error, I also need
to configure the VB project to include "Excel" as follows.
1. Project>References to open the References dialog box.
2. select "Microsoft Excel 9.0 object library"
I did not manage to find a corresponding object library (i.e.
WScript.Network) in VB>Project>Reference.
I feel that it is important to understand this to improve my
programming skill and write better program. Pls help. Thank you very
much.
"Alan Barker" <Az*****@hotmailREMOVEME.com> wrote in message news:<c9**********@sparta.btinternet.com>... Alex, it very similar to the vbscript you have already,
Dim WshNetwork ' COULD SET AS TYPE: OBJECT otherwise its a variant Set WshNetwork = CreateObject("WScript.Network") ' THIS LINE DIFFERS SLIGHTLY: Note the CreateObject msgbox("Enter password")
WshNetwork.MapNetworkDrive "J:", "\\server1\data", False, "xyz_net\John", sPwd MsgBox "Drives has been map successful"
Set WshNetwork = Nothing ' BEST TO RELEASE THE OBJECT (FREE UP RESOURSES)
hope it helps al.
"Alex Ang" <Al*******@yahoo.com.sg> wrote in message news:13**************************@posting.google.c om... I have written the following VBScript program. It is stored into a file "map_drive.vbs". It successfully mapped to a network drive \\server1\data.
Dim WshNetwork Set WshNetwork = WScript.CreateObject("WScript.Network") sPwd = inputbox("Enter password") WshNetwork.MapNetworkDrive "J:", "\\server1\data", false, "xyz_net\John", sPwd Msgbox "Drives has been map successful"
Could anyone teach me how to convert it to a Visual Basic program such that it can be compiled to an .exe file? I tried to use Active X Control - Windows Script Control 1.0. But I couldn't make it work. Perhaps, I do not know how to use the Script Control, or it is a totally wrong approach. It will be nice if you can give Step-by-step instructions. Please help. Thanks a lot.
Alex Ang wrote: Thanks Alan, my program can run now. :) Thanks Randy for your suggestion too.
I have another question regarding Dim. Why can't I do the following. Dim WshNetwork As WScript.Network ‘Compile Error: User Defined Type Not Define
Select "Windows Scripting Host ..." in Project -> References.
Change your code to
Dim WshNetwork As WshNetwork
Set WshNetwork = New WshNetwork
or shorter:
Dim WshNetwork As New WshNetwork
However the following is all right. Dim WshNetwork As Object ‘NO error. Set WshNetwork = CreateObject("WScript.Network")
I was trying the above because I did something similar that make use of "Excel" object. The VB code is as follows: Dim XLObj As Excel.Application Set XLObj = CreateObject("Excel.Application")
For shorter,
Dim XLObj As New Excel.Application
To make the above VB code run without error, I also need to configure the VB project to include "Excel" as follows. 1. Project>References to open the References dialog box. 2. select "Microsoft Excel 9.0 object library"
CreateObject() just makes it possible to use objects only at run-time
without the reference library at design time. There is no practical
difference when the program is running.
I did not manage to find a corresponding object library (i.e. WScript.Network) in VB>Project>Reference. I feel that it is important to understand this to improve my programming skill and write better program. Pls help. Thank you very much.
To use WScript.* and Scripting.* objects, reference "Windows Scripting
Host".
--
Olof Lagerkvist
ICQ: 724451
Web page: http://here.is/olof
Alex, you can reference the Wsh Object just like you did with the Excel
object. The reference is
Windows Script Host Object Model
and can be found lurking towards the bottom of the references list.
Its a little different than using the createobject method earlier but with
the Intellisense now working (because you have told VB what type of object
it is) you will find it a lot easier.
The network object is WshNetwork so; your code should now resemble
Dim a As WshNetwork
Set a = New WshNetwork
a.MapNetworkDrive "I:", \\server\folder, False, "domain\username",
"password"
Set a = Nothing ' clean up
------------------------
to further your understanding, when you use the createobject function it
asks the system to do a lookup for any installed ActiveX components with the
name 'wscript.network'. This list is in the HKey Classes Root hive of the
registry (do a search with regedit). In this key it will point to the
wshom.ocx in the system folder. This file is the same file you 'reference'
when you use the alternate method above.
Because you already 'reference' the wshom.ocx you need not call the
createobject function: you are telling VB in advance what object you are
going to create, this is known as early binding.
both methods have the same result but the one above is much faster.
if you need any further info just ask,
al.
"Alex Ang" <Al*******@yahoo.com.sg> wrote in message
news:13*************************@posting.google.co m... Thanks Alan, my program can run now. :) Thanks Randy for your suggestion too.
I have another question regarding Dim. Why can't I do the following. Dim WshNetwork As WScript.Network 'Compile Error: User Defined Type Not Define
However the following is all right. Dim WshNetwork As Object 'NO error. Set WshNetwork = CreateObject("WScript.Network")
I was trying the above because I did something similar that make use of "Excel" object. The VB code is as follows: Dim XLObj As Excel.Application Set XLObj = CreateObject("Excel.Application")
To make the above VB code run without error, I also need to configure the VB project to include "Excel" as follows. 1. Project>References to open the References dialog box. 2. select "Microsoft Excel 9.0 object library"
I did not manage to find a corresponding object library (i.e. WScript.Network) in VB>Project>Reference. I feel that it is important to understand this to improve my programming skill and write better program. Pls help. Thank you very much.
"Alan Barker" <Az*****@hotmailREMOVEME.com> wrote in message
news:<c9**********@sparta.btinternet.com>... Alex, it very similar to the vbscript you have already,
Dim WshNetwork ' COULD SET AS TYPE: OBJECT otherwise its a variant Set WshNetwork = CreateObject("WScript.Network") ' THIS LINE DIFFERS SLIGHTLY: Note the CreateObject msgbox("Enter password")
WshNetwork.MapNetworkDrive "J:", "\\server1\data", False,
"xyz_net\John", sPwd MsgBox "Drives has been map successful"
Set WshNetwork = Nothing ' BEST TO RELEASE THE OBJECT (FREE UP
RESOURSES) hope it helps al.
"Alex Ang" <Al*******@yahoo.com.sg> wrote in message news:13**************************@posting.google.c om... I have written the following VBScript program. It is stored into a file "map_drive.vbs". It successfully mapped to a network drive \\server1\data.
Dim WshNetwork Set WshNetwork = WScript.CreateObject("WScript.Network") sPwd = inputbox("Enter password") WshNetwork.MapNetworkDrive "J:", "\\server1\data", false, "xyz_net\John", sPwd Msgbox "Drives has been map successful"
Could anyone teach me how to convert it to a Visual Basic program such that it can be compiled to an .exe file? I tried to use Active X Control - Windows Script Control 1.0. But I couldn't make it work. Perhaps, I do not know how to use the Script Control, or it is a totally wrong approach. It will be nice if you can give Step-by-step instructions. Please help. Thanks a lot.
Alan, Thanks for the explanation. :) Now, I can tell the differences
in VB code between "late binding" and "early binding".
However, I'm afraid I still do NOT understand the following.
Example 1:
Why it should be -
Dim a As WshNetwork
NOT - Dim as As WScript.Network ‘user define type error
Example 2: The Excel object can be Dim in both ways without errors.
Dim XLobj As Excel.Application
‘Dim XLobj As Application is ok too.
Set XLObj = New Excel.Application
‘Set XLObj = New Application is ok too
Why does Excel.Application can be Dim in either ways? Whereas
WshNetwork cannot?
Based on "Windows Script v5.6" documentation" download from MS web
sit, I thought it should be "WScript.Network". This is because the
documentation shows the following diagram for the "Windows Script Host
Object Model". See diagram below.
The Windows Script Host object model consists of 14 objects.
The root object is the WScript object.
WScript
!
+-----WshArguments
!
+-----WshController
!
+-----WshNetwork
Based on the above diagram, I will write the following VB code.
WScript.WshNetwork
because WScript is the ROOT and it contains WshNetwork.
Note: I have this "understanding" of writing VB code in
objectX.objectY.property - "Object hierarchy" (nested object) - from
some ADO programming experience such as the following:
adoFriends.Recordset.MoveLast
I guess I do NOT have adequate understanding on "Object Hierarchy"
etc. Hence, it gives me many problems when writing VB code that duels
with Objects hierarchy, etc.
Pls help. Thanks a lot.
"Alan Barker" <Az*****@hotmailREMOVEME.com> wrote in message news:<c9**********@sparta.btinternet.com>... Alex, you can reference the Wsh Object just like you did with the Excel object. The reference is Windows Script Host Object Model and can be found lurking towards the bottom of the references list.
Its a little different than using the createobject method earlier but with the Intellisense now working (because you have told VB what type of object it is) you will find it a lot easier. The network object is WshNetwork so; your code should now resemble
Dim a As WshNetwork
Set a = New WshNetwork a.MapNetworkDrive "I:", \\server\folder, False, "domain\username", "password"
Set a = Nothing ' clean up
> However, I'm afraid I still do NOT understand the following. Example 1: Why it should be - Dim a As WshNetwork NOT - Dim as As WScript.Network 'user define type error
Example 2: The Excel object can be Dim in both ways without errors. Dim XLobj As Excel.Application 'Dim XLobj As Application is ok too.
Set XLObj = New Excel.Application 'Set XLObj = New Application is ok too
Why does Excel.Application can be Dim in either ways? Whereas WshNetwork cannot?
Based on "Windows Script v5.6" documentation" download from MS web sit, I thought it should be "WScript.Network". This is because the documentation shows the following diagram for the "Windows Script Host Object Model". See diagram below.
The Windows Script Host object model consists of 14 objects. The root object is the WScript object.
WScript ! +-----WshArguments ! +-----WshController ! +-----WshNetwork
Based on the above diagram, I will write the following VB code. WScript.WshNetwork because WScript is the ROOT and it contains WshNetwork.
Note: I have this "understanding" of writing VB code in objectX.objectY.property - "Object hierarchy" (nested object) - from some ADO programming experience such as the following: adoFriends.Recordset.MoveLast
I guess I do NOT have adequate understanding on "Object Hierarchy" etc. Hence, it gives me many problems when writing VB code that duels with Objects hierarchy, etc. Pls help. Thanks a lot.
<snip>
when you use the createobject function you need specify what COM server you
are starting and what object you are going create from that server.
so in this case using the createobject method you will specify the COM
server: Wscript and then the Object from the server: WshNetwork hence
Wscript.WshNetwork.
however; when using visual basic you create a 'reference' to the WScript
object in the references page. The object may be Called 'Windows Script Host
Object Model' and have a filename of wshom.ocx but it is the Wscript object.
Because you have now added a reference to this object within VB you no
longer need to prefix any of its objects with the name so Wscript.WshNetwork
becomes WshNetwork.
CreateObject does not use the look at the references in VB so you need still
need to provide the full object hierarchy.
As for the Excel example; This is a little more tricky. You are correct,
declaring Excel.Application or just Application on it's own has the same
effect; this is because although Excel appears in the list of types when you
declare it cannot be declared alone i.e. Dim obj as Excel. The reason for
this is that Excel here is a Type or object library *containing* the type
Application. Also because the Excel object is now referenced in VB it also
just displays the Excel Objects. My bet is if you were to also add a
reference to MS Word in the project as well you would have TWO 'Application'
Types listed Together. You would not be able to distinguish the two (and
neither would VB) try it:
Add a reference to MS Word and MS Excel
Dim ExcelObj As New Application '<- Select first from type list
Dim WordObj As New Application '<- select second from type list
Debug.Print ExcelObj.Name
Debug.Print WordObj.Name
You will notice the same name, so change the declares to
Dim ExcelObj As New Excel.Application
Dim WordObj As New Word.Application
Now you have the desired result.
Your object hierarchy understanding is perfectly ok.
finally, returning to Why it should be - Dim a As WshNetwork NOT - Dim as As WScript.Network 'user define type error
it can be, but...
unlike the Excel Library above, for some reason Microsoft did not name
the WScript library 'WScript' but Instead named it 'IWshRuntimeLibrary' !
so (eventually)
Dim obj as new IWshRuntimeLibray.WshNetwork
--------------------------------
Hope I didn't confuse,bore,over complicate etc
any further info just ask,
Apologies for the size of post,
Al.
Alan, Thanks for the explanation. :) Now, I can tell the differences
in VB code between "late binding" and "early binding".
However, I'm afraid I still do NOT understand the following.
Example 1:
Why it should be -
Dim a As WshNetwork
NOT - Dim as As WScript.Network ‘user define type error
Example 2: The Excel object can be Dim in both ways without errors.
Dim XLobj As Excel.Application
‘Dim XLobj As Application is ok too.
Set XLObj = New Excel.Application
‘Set XLObj = New Application is ok too
Why Excel.Application can be Dim in either ways? Whereas WshNetwork
cannot?
Based on "Windows Script v5.6" documentation" download from MS web
sit, I thought it should be "WScript.Network". This is because the
documentation shows the following diagram for the "Windows Script Host
Object Model".
The Windows Script Host object model consists of 14 objects.
The root object is the WScript object.
WScript
!
+-----WshArguments
!
+-----WshController
!
+-----WshNetwork
Based on the above diagram, I will write the following VB code.
WScript.WshNetwork
because WScript is the ROOT and it contains WshNetwork.
Note: I have this "understanding" of writing VB code in
objectX.objectY.property - "Object hierarchy" (nested object) - from
some ADO programming experience such as the following:
adoFriends.Recordset.MoveLast
I guess I do NOT have adequate understanding on "Object Hierarchy"
etc. Hence, it gives me many problems when writing VB code that duels
with Objects hierarchy, etc.
Pls help. Thanks.
"Alan Barker" <Az*****@hotmailREMOVEME.com> wrote in message news:<c9**********@sparta.btinternet.com>... Alex, you can reference the Wsh Object just like you did with the Excel object. The reference is Windows Script Host Object Model and can be found lurking towards the bottom of the references list.
Its a little different than using the createobject method earlier but with the Intellisense now working (because you have told VB what type of object it is) you will find it a lot easier. The network object is WshNetwork so; your code should now resemble
Dim a As WshNetwork
Set a = New WshNetwork a.MapNetworkDrive "I:", \\server\folder, False, "domain\username", "password"
Set a = Nothing ' clean up
------------------------ to further your understanding, when you use the createobject function it asks the system to do a lookup for any installed ActiveX components with the name 'wscript.network'. This list is in the HKey Classes Root hive of the registry (do a search with regedit). In this key it will point to the wshom.ocx in the system folder. This file is the same file you 'reference' when you use the alternate method above.
Because you already 'reference' the wshom.ocx you need not call the createobject function: you are telling VB in advance what object you are going to create, this is known as early binding.
both methods have the same result but the one above is much faster.
if you need any further info just ask, al.
"Alex Ang" <Al*******@yahoo.com.sg> wrote in message news:13*************************@posting.google.co m... Thanks Alan, my program can run now. :) Thanks Randy for your suggestion too.
I have another question regarding Dim. Why can't I do the following. Dim WshNetwork As WScript.Network 'Compile Error: User Defined Type Not Define
However the following is all right. Dim WshNetwork As Object 'NO error. Set WshNetwork = CreateObject("WScript.Network")
I was trying the above because I did something similar that make use of "Excel" object. The VB code is as follows: Dim XLObj As Excel.Application Set XLObj = CreateObject("Excel.Application")
To make the above VB code run without error, I also need to configure the VB project to include "Excel" as follows. 1. Project>References to open the References dialog box. 2. select "Microsoft Excel 9.0 object library"
I did not manage to find a corresponding object library (i.e. WScript.Network) in VB>Project>Reference. I feel that it is important to understand this to improve my programming skill and write better program. Pls help. Thank you very much.
"Alan Barker" <Az*****@hotmailREMOVEME.com> wrote in message news:<c9**********@sparta.btinternet.com>... Alex, it very similar to the vbscript you have already,
Dim WshNetwork ' COULD SET AS TYPE: OBJECT otherwise its a variant Set WshNetwork = CreateObject("WScript.Network") ' THIS LINE DIFFERS SLIGHTLY: Note the CreateObject msgbox("Enter password")
WshNetwork.MapNetworkDrive "J:", "\\server1\data", False, "xyz_net\John", sPwd MsgBox "Drives has been map successful"
Set WshNetwork = Nothing ' BEST TO RELEASE THE OBJECT (FREE UP RESOURSES) hope it helps al.
"Alex Ang" <Al*******@yahoo.com.sg> wrote in message news:13**************************@posting.google.c om... > I have written the following VBScript program. It is stored into a > file "map_drive.vbs". It successfully mapped to a network drive > \\server1\data. > > Dim WshNetwork > Set WshNetwork = WScript.CreateObject("WScript.Network") > sPwd = inputbox("Enter password") > WshNetwork.MapNetworkDrive "J:", "\\server1\data", false, > "xyz_net\John", sPwd > Msgbox "Drives has been map successful" > > Could anyone teach me how to convert it to a Visual Basic program such > that it can be compiled to an .exe file? > I tried to use Active X Control - Windows Script Control 1.0. But I > couldn't make it work. Perhaps, I do not know how to use the Script > Control, or it is a totally wrong approach. It will be nice if you can > give Step-by-step instructions. > Please help. Thanks a lot.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: AES/newspost |
last post by:
I'd like to generate a site map or some kind of cascaded outline or tree
diagram of a web site stored in a folder on a Mac under OS 9, showing
the file names and the links or hierarchical relations...
|
by: William Payne |
last post by:
Hello, I have a variable of type unsigned long. It has a number of bits set
(with set I mean they equal one). I need to determine those bits and their
position and create new numbers from them. For...
|
by: Mosher |
last post by:
Hi all, is there a good way to have a popup window appear using Javascript
and the html "map" tag? Here is my code:
<map name="navigation">
<area shape="rect" coords="5,57,45,70"...
|
by: Diwa |
last post by:
Does the "value" type (value as in key-value pair )of "std::map"
require a default ctor even if it is not used ?
If I comment out Line 1 in the code attached later,
i.e remove the default ctor...
|
by: Thembi |
last post by:
I wanna know if ,the map stores sorted data or not.
|
by: siva07 |
last post by:
Hi experts
i want get a folder which is outside the root directory that is i use as a private directory
help me
Thanks
|
by: tshad |
last post by:
How can I fix this error?
I am on an XP and tried to right-click the uploads folder to find the
security tab, but it isn't there.
In IIS6, I have write access checked.
How can I give ASPNET...
|
by: moodyman13 |
last post by:
Hi all,
Hoping someone can help me. I'm using WSH to automatically map a network drive when someone opens a webpage. Below are the codes
<HTML>
<Body>
<script language="VBScript"...
|
by: William Manley |
last post by:
Lately I've been thinking of trying to make a map for a game I play. The current maps are all images, they are basically just tiles each. I'd want to be able to have each tile its own small image so...
|
by: Rina0 |
last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |