Xcopy problems..

im_caius

Distinguished
Sep 15, 2010
118
0
18,680
xcopy "C:\run.bat" "AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\" /y /i

That is what I've got..
But instead of copying 'run.bat' to the Startup folder.. it copies "AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\" to the C: drive..
What have I done wrong?
 

im_caius

Distinguished
Sep 15, 2010
118
0
18,680
where you say Username you mean to write the username right?
Because I want it to work on many computers (all with different usernames)
So I'm really not sure what to do..
Even when I replace AppData with %AppData% it doesn't work..
 

im_caius

Distinguished
Sep 15, 2010
118
0
18,680
Ok, new problem..
I want to do it from inside VB without the external batch file..
and I have to type:
Process.Start "cmd.exe" "/C xcopy "C:\run.bat" "C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\run.bat" /y"

but the problem is, it thinks im closing the wrong things..
Like it things this is what I'm closing..
"/C xcopy " and then C:\run.bat isn't enclosed in the marks, and then " " is the next one..
Well I think you get the point.. any ideas on what I can do?
 

dmroeder

Distinguished
Jan 15, 2005
1,366
23
20,765
This should work. You can call it with a button by putting "CopyFile" in your button_click code. Or you could just put all the code within the sub directly into the button if you would like.

If you don't mind me asking, what are you intending your batch file to do?

Private Sub CopyFile()

'Get the current users startup path. It will look like this:
'C:\Users\*Current User*\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
Dim strStartupFolder As String = System.Environment.GetFolderPath(Environment.SpecialFolder.Startup)

'The destination for the batch file. It will look like this:
'C:\Users\*Current User*\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\run.bat
Dim strDestination As String = strStartupFolder & "\run.bat"

'The file to copy
Dim strFileToCopy As String = "C:\run.bat"

'If the file does not already exist, copy the batch file to the startup path
If File.Exists(strDestination) = False Then
File.Copy(strFileToCopy, strDestination)
End If

End Sub