Jump to content

Recommended Posts

Posted

I guess you are trying to map a network drive?

 

Its been a long time since I did much programming but aren't these just commonly used variable names used when mapping network drives?

 

Essentially theres no difference as they could be called anything.

So if you are trying to map a network drive you would something like:

 

Option Explicit

Dim objWshNetwork (declare var - could be anything)

Set objWshNetwork = CreateObject("WScript.Network") (assign var)

objWshNetwork.MapNetworkDrive("x:","\\Server\Share")

Posted

what is the difference between these

"objnetwork" and "wshnetwork"

 

many thanks

 

As per above they are just variables - you can call it network or mynetwork or whatever you want as long as when you create the object you use the same name for example

 

[b]Dim Network[/b]
[b]Set Network[/b] = CreateObject("WScript.Network")

[b]Network[/b].MapNetworkDrive("x:",[url="file://\\Server\Share"]\\Server\Share [/url]) 

 

As you can see I have declared Network using the Dim statement, I have then used the Set statement to Set the Network variable so it is equal to the network object which you have to create using CreateObject("WScript.Network")

 

Then when you want to use the Network variable to do something you put Network.Property

 

Property could be UserName, MapNetworkDrive or whatever property you want to use that is related to the network object as long as its used in the correct way

Posted

One of the things that can be really confusing in programming in VBScript is the use of variable names; people generally have their own way of naming things but the growth of the internet has meant that most people copy bits of code and edit it - this seems to have lead to certain variables gaining dominance so it looks as if the name matters.

 

In a statement like:

set oNet = CreateObject("wscript.network")

the bit that matters is on the right - you're working with that specific object but you can call it oNet, Network, objNetwork, tom, dick or harry but once you've chosen the name you need to stick with that name while you work with it.

 

set oFSO=createobject("scripting.filesystemobject")
set oFile1=ofso.opentextfile("c:\temp\data.txt")
set oFile2=ofso.opentextfile("c:\temp\data.txt")
sLine1=oFile1.readline
wscript.echo sLine
oFile1.close
sLine2=oFile2.readline
oFile2.close

 

In the example above, oFile1 and oFile2 are both file objects; they both refer to the same file on disc but they're not the same thing - when I read a line from oFile1 it doesn't do anything to oFile2. When I close oFile1 it doesn't affect oFile2 etc.

Posted
One of the things that can be really confusing in programming in VBScript is the use of variable names; people generally have their own way of naming things but the growth of the internet has meant that most people copy bits of code and edit it - this seems to have lead to certain variables gaining dominance so it looks as if the name matters.

 

Agreed, it appears that objnetwork and wshnetwork have become commonly used, the misunderstanding is understandable.

  • 1 year later...
Posted

Hello,

 

I am kind of new to programming but it looks interesting as i want to make an script for my WMI filter.

 

i want to use a WMI filter to look into the department field and if there is a user with department field set to sales than he should get"policy 1"

and if the user is in production than the user should get "policy 2"

but i just can not figure out where i can get the object from department field :(

can some one help me on the way?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...