Solved

File System object in VbScript

Posted on 2004-08-17
4
237 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 125 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month8 days, 2 hours left to enroll

617 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