InterviewSolution
| 1. |
Solve : VB script copying across networks? |
|
Answer» hey all, The red line brings up an error saying "access is denied", but i know that the username and password to be right. Quote I have checked and i can map to 10.1.0.100\c$ from a run box, (windows does ask for the guest password - which i don't know!) These statements seem contradictory. Do you know the user & password? Is there a user & password? Quote have i got them the wrong way round???UserID and password are in the correct order. Whether they have the correct values is the question. Do not use parenthesis for MapNetworkDrive or Copyfile. When I tried your code, I got a syntax error. Also it's set fso.....you are creating an instance of the FileSystemObject not equating two variables. Code: [Select]Dim fso, WshNetwork Const OverwriteExisting = True WshNetwork = CreateObject("wscript.network") Set fso = CreateObject("scripting.filesystemobject") WshNetwork.mapnetworkdrive "x:", "\\10.1.0.100\c$", , "username", "password" fso.CopyFile "C:\batch\remote.bat", "x:\remote.bat", OverwriteExisting MessageBox.Show("Transfer Complete") You never told us whether you're using wscript or cscript. That "unauthorizedAccessException was unhandled" message still has me puzzled. Yes, the user name and password are right. I can map to the path in the script (\\10.1.0.100\c$) but when the authentication windows pops up it has the \\computer name\guest inserted in the username and it's grayed out so i can't change it. Since there is no password on the guest account and you can't leave the authentication password field empty when mapping, i can't open the c:\. Hence why i use an admin account, both of the machines that I'm using are mine, so i have full access to all accounts. As to your question about weather i'm using wscript or cscript, thb i don't know!!!! I have installed Microsoft visual basic 2005 SP1, I opened it up and then opened a new project. (if there's a way of telling let me know and I'll check for you.) I have this code inserted under a handle of button4 (click) Dim fso, WshNetwork Const OverwriteExisting = True WshNetwork = CreateObject("wscript.network") Set fso = CreateObject("scripting.filesystemobject") WshNetwork.mapnetworkdrive "x:", "\\10.1.0.100\c$", , "username", "password" fso.CopyFile "C:\batch\remote.bat", "x:\remote.bat", OverwriteExisting MessageBox.Show("Transfer Complete") The set that you refer to keeps disappearing after i put it in. (i have copied your code and replaced it for mine, But i still get strange errors like, "access denied" and "path not found". I have tried subbing the c:\ on the remote machine for a newly made e:\ thats shared, but it made no difference. (also tried to map to the e:\ but still got the guest username inserted in the user field) I have also tried to use the computer name instead of the ip but as I'm on a LAN VPN extension from work, (where there is another Pc with the same name) it keeps saying "access denied" As i said yesturday I have only just started using vb so i'm a complete newbee, (but i'm willing to try to work it out for my self) If there is anything else that you can suggest, (i might start a new project and just have that simple code to get to work first before making the form menu.) that would help i would forever be in your debt. Thanks again Quote I have installed Microsoft visual basic 2005 SP1I suspected as much. You are using VB.Net which is a full fledged programming language. You can certainly use VB.Net for your project, but if all you need is to copy a file(s) across the network, VBScript is much easier and a LOT less overhead. Plus there is none of that pesky compiling and linking. To use VBScript, copy & paste the code that has been posted into your editor (Notepad works fine). Save the script with a VBS extension. Open up a command prompt and run the script as: cscript scriptname.vbs You can learn all about VBScript at the Microsoft Script Center. Good luck. cheers, I'm gonna to do that for this, but also have a larger program in mind. I currently have about 7/8 batch files that transfer files and run batch files on remote machines. I then have a menu.bat that simply points to the files needed for the operation that you've requested. Due to it getting bigger and bigger and because of my staff needing to use it as well, I require a windows based grafical interface. I think i'll just start by having bguttons on the from and then when clicked openning the batch file that deals with it. once i've read up some more i move to converting the batch files them-selfs to vb script. Thanks very much for your time and effort. (if i manage to accomplish this any time soon I'll post on this thread.) |
|