Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

where is my mistake?

Status
Not open for further replies.

DgtlLgk

Technical User
May 3, 2004
52
CY
not a vbscript guy:)....(wish i was)
iam trying to make a backup script.ive managed with a lot of reading online to create this.my nas createw a folder of the user that is logging on


' ----------------------------------------------------------------------'
Option Explicit
Dim objNetwork, objShell, objFolder, objFile
Dim objFso, alreadyConnect, strTargetFolder, strFileToMove
Dim strDriveLetter, strRemotePath, strUser, strPassword, strProfile, strUsr, strPwd

'Values of variables set
WScript.Echo "Please close any files or program you have open"

strDriveLetter = "P:"

strUsr = InputBox("Please Enter Your Authenticated Username")
strPwd = InputBox("Please enter your Authenticated Password:")
strRemotePath = "\\remote server\" & strUsr
strProfile = "false"

'This section creates a network object
'Then apply MapNetworkDrive . Result P: drive
Set objNetwork = WScript.CreateObject("WScript.Network")
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, _
strProfile, strUsr, strPwd

'add a message box
WScript.Echo " Map drive letter: "& strDriveLetter

WScript.Echo "Please wait until 'finish copying files' message appears"

This is to show the progress bar(found it on internet:))
strTargetFolder = "\\remote server\" & strUsr
If Right(strTargetFolder, 1) <> "\" Then strTargetFolder = strTargetFolder & "\"
Const FOF_CREATEPROGRESSDLG = &H10&

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Shell.Application")

Set objFolder = objShell.NameSpace(strTargetFolder)

strFileToMove = "C:\test"
Set objFile = objFSO.GetFolder(strFileToMove)

If Not objFolder Is Nothing Then
objFolder.CopyHere objFile.Path, FOF_CREATEPROGRESSDLG
Else
MsgBox "There was an error finding " & strTargetFolder
End If

if all are ok
WScript.Echo "finish copying files"

'disconnect map drive
If strDriveLetter = "P:" then
objNetwork.RemoveNetworkDrive "P:" 'here i get the error that there are still open files, and all are stopped
Else
End if

WScript.Quit
 
Why create a map drive you don't use ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
this whole strDriveLetter stuff doesnt make sense to me.
you explicitly set the drive letter to P, then check if you have set it to P (which of course you have)

strDriveLetter = "P:"
'
'
If strDriveLetter = "P:" then
objNetwork.RemoveNetworkDrive "P:" 'here i get the error that there are still open files, and all are stopped
Else
End If

'''this would be better?
strDriveLetter = "P:"
'
'
objNetwork.RemoveNetworkDrive strDriveLetter

'be careful that the P drive isnt in use before you try and connect using it...
'i would advise against the use of drive letters, you dont need them, just use the \\servername\sharename. you can always use NET USE \\servername\sharename with the credentials you which


 
Thanx guys for your response

something i didnt make clear.as i log on to my nas machine, it automatically creates the folder as the user name is.i have already created the users on the nas, so each one will have access to his/her folder only.

this as i said i found it online and i thought that it is necessary for the progress bar to work
strTargetFolder = "\\remote server\" & strUsr
If Right(strTargetFolder, 1) <> "\" Then strTargetFolder = strTargetFolder & "\"


i do a map drive, because many users are not so computer literal.so in any time i need to report for their 'backup place' in their 'my computer' i say the P drive.there is another case that i can re map their backup folder for a reason, and then disconnect it as i try to do.
i disconnect the map drive so they don't mess with their backup(there are some reasons)

any more suggestions will be appreciated
 
i think ,what i need is how to end/close the session with the files i transfer from the pc to the remote location
 
>what i need is how to end/close the session with the files i transfer from the pc to the remote location
What do you mean? The "session" will end by its own when the copying is all done.

>this as i said i found it online and i thought that it is necessary for the progress bar to work
strTargetFolder = "\\remote server\" & strUsr
If Right(strTargetFolder, 1) <> "\" Then strTargetFolder = strTargetFolder & "\"
I don't think so. Besides, and quite independent of whether that belief is right or wrong, you don't expect user will enter their username with a trailing backslash, neither, do you?

>Const FOF_CREATEPROGRESSDLG = &H10&
No, this is not what would give you the behaviour with "progress bar". The correct value is given by the &H0&.
[tt]
Const FOF_CREATEPROGRESSDLG = &H0&
Const FOF_NOCONFIRMATION = &H10&
[/tt]
>i do a map drive, because many users are not so computer literal.
But users do not intervene where and what to copy to in the script. It does not matter whether they are computer literate or not, does it? So the whole business of mapping should not appear.
 
ok guys.thanx a lot.i will give it a try with your suggestions tomorrow, and i 'll let you know.thanx again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top