Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

File System object in VbScript

Posted on 2004-08-17
4
Medium Priority
?
243 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
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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

971 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