Vb script to check the environment variable and copy files.
I need a vb script that checks the environment varable fro e.g "user_pro" where user_pro will have value based on the region (for e.g gid and zip). If user_pro is "gid" then copy files to the network path. and this should work when i launch the shortcut.
thanks
thanks
0 Comments
[ + ] Show comments
Answers (4)
Please log in to answer
Posted by:
mayur_mak
13 years ago
Hi
Chk the following Script if it suits .as per yr requirement modify it
U need to do error handling based upon the requirement
Set objShell = WScript.CreateObject("WScript.Shell")
Set goFSO = CreateObject("Scripting.FileSystemObject")
strRegKeyValue = objShell.RegRead ("HKLM\SYSTEM\CurrentControlSet\Control\SessionManager\Environment\user_pro")
'1)Chk here whether network is online
'2)Chk whether required folder exsits on the network where files needs to be copied
'3)run the main shortcut even if error during copy or not
'4)Here file_path_main is the location of the shortcut EXE
If strRegKeyValue = "gid" Then
dest_loc = 'your orginal file path which needs to be copied
goFSO.CopyFile str_server_file_loc, dest_loc, True
Wscript.Sleep 500 'time interval depends upon the number of files and size
objShell.run Chr(34) & file_path_main & Chr(34)
End If
regards,
Mayur Makwana
Chk the following Script if it suits .as per yr requirement modify it
U need to do error handling based upon the requirement
Set objShell = WScript.CreateObject("WScript.Shell")
Set goFSO = CreateObject("Scripting.FileSystemObject")
strRegKeyValue = objShell.RegRead ("HKLM\SYSTEM\CurrentControlSet\Control\SessionManager\Environment\user_pro")
'1)Chk here whether network is online
'2)Chk whether required folder exsits on the network where files needs to be copied
'3)run the main shortcut even if error during copy or not
'4)Here file_path_main is the location of the shortcut EXE
If strRegKeyValue = "gid" Then
dest_loc = 'your orginal file path which needs to be copied
goFSO.CopyFile str_server_file_loc, dest_loc, True
Wscript.Sleep 500 'time interval depends upon the number of files and size
objShell.run Chr(34) & file_path_main & Chr(34)
End If
regards,
Mayur Makwana
Posted by:
anonymous_9363
13 years ago
Almost, but I'm guessing that the OP would want to have more than one region so, rather than a single 'If...End If', he'd require a 'Select Case' construct:
Lastly, note the use of AD's CODE tag! :-)
Select Case strRegKeyValue
Case "gid"
dest_loc = "somewhere"
Case "zip"
dest_loc = "somewhere_else"
Case Else
dest_loc = "some_default_place"
End Select
goFSO.CopyFile str_server_file_loc, dest_loc, True
<etc, etc>
I have *no* idea why you have included a Sleep method: the 'Run' line won't execute until the file copy operation is complete.Lastly, note the use of AD's CODE tag! :-)
Posted by:
mayur_mak
13 years ago
@VBscab
I agree with you.
This is just a basic script and not a full fledged script.Its for only understanding purpose.
Since it is not clearly specified whether the shortcut will perform only copy task while launching or after copy it will run the shortcut exe file.As a result a run command is included.
regards
Mayur MAkwana
I agree with you.
This is just a basic script and not a full fledged script.Its for only understanding purpose.
Since it is not clearly specified whether the shortcut will perform only copy task while launching or after copy it will run the shortcut exe file.As a result a run command is included.
regards
Mayur MAkwana
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.