Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

File System object in VbScript

Posted on 2004-08-17
4
Medium Priority
?
239 Views
Last Modified: 2010-05-02
I have a piece of code that will read a folder and check each file's modified date. I want to read a file that exists on a server that is on a different domain. I have a specific login, password and domain that I use to map this drive manually.

Is there a way to pass a login/password/domain to the VBScript GetFolder method? Or some alternative that will allow me to read files on this remote server?

Here is the code that I am using. As long as the user that executes this code has permissions on this folder, I am fine. But when I move out of the domain, the code fails due to permissions errors.

            Set fso = CreateObject ("Scripting.FileSystemObject")
            filePath = AryDrives(x)
            Set f = fso.GetFolder(filePath)
0
Comment
Question by:netlisa22
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 11

Expert Comment

by:coopzz
ID: 11826957
If you are doing this to only one other domain the quick and easy way would be to wrap the FilesystemObject into another Com object and create a new application in com+ services. Change the Identity to suit the proper authorisation and you should get access. worked for me.

0
 
LVL 76

Accepted Solution

by:
David Lee earned 375 total points
ID: 11829023
Use Windows Scripting Host's NetWork object and call the MapNetworkDrive method.  Something like this:

strDriveLetter = "X:"     'Use whatever drive letter you want
strRemoteShare = "\\MyServer\MyShare"
strUserName = "A username with dufficient privileges"
strPassword = "The password associated with strUserName"
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.MapNetworkDrive strDriveLetter, strRemoteShare, strUserName, strPassword
'Code to work with the files
WshNetwork.RemoveNetworkDrive strDriveLetter

Just remember that storing the username and password in a script file means they can be seen by anyone who can get to the script file itself.

Here's a link to the details of MapNetworkDrive on MSDN
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/wsmthmapnetworkdrive.asp
0
 
LVL 11

Expert Comment

by:coopzz
ID: 12378381
Well I know the solution I provided works (I use it)

>>Or some alternative that will allow me to read files on this remote server?

and it is an alternative.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question