Solved

File System object in VbScript

Posted on 2004-08-17
4
220 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
  • 2
4 Comments
 
LVL 11

Expert Comment

by:coopzz
Comment Utility
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 125 total points
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now