Copy File - but need Environment Variable - VS 2005

oceaniana

Member
Joined
Apr 1, 2006
Messages
11
Programming Experience
Beginner
Hello
I need help on the below code, im a absolute noob please be kind
I'll try to explain what im trying to do, XXXXX below needs to be replaced with path to SystemDrive, but i cant use %SystemDrive% Environment Variable, i cant use C:\ as it is a fixed path(not all PC's have xp on c drive)
All i got to do is copy a file from my burnt cd (some Path) with my app to various xp installs
VB.NET:
Public Sub Button20_Click() Handles Button20.Click
        Dim str As [String]
        Dim query As [String] = "%SystemDrive%"
        str = Environment.ExpandEnvironmentVariables(query)
        My.Computer.FileSystem.CopyFile("Register.key", "XXXXX\Program Files\Register.key")
End Sub
I know i sux at coding, but if anyone can help please please could u have full example. I appreciate any kind of feed back.
Thank You
:D
 

oceaniana

Member
Joined
Apr 1, 2006
Messages
11
Programming Experience
Beginner
Solved

I figured it out [:p]
VB.NET:
        Dim str As String
        Dim origFile As String = "1"
        Dim query As String = "%SystemDrive%"
        Dim copiedFile As String = "\Register.key"
        str = Environment.ExpandEnvironmentVariables(query)
        My.Computer.FileSystem.CopyFile(origFile, str + copiedFile)
[:D]
 

oceaniana

Member
Joined
Apr 1, 2006
Messages
11
Programming Experience
Beginner
Need More Help

I need help AGAIN, please help.
I cant figure out how to just call a file by using a EnviorememtVariable to execute a file
Below is first bit, wont work

VB.NET:
        Dim str As String
        Dim query As String = "%SystemDrive%"
        Dim sourceFile As String = "\WINDOWS\PCHealth\HelpCtr\Binaries\helpctr.exe"
        Dim addEmUp As String = "str + sourceFile"
        Str = Environment.ExpandEnvironmentVariables(query)
        Process.Start("addEmUp")


I tried this aswell, wont work

VB.NET:
        Dim str As String
        Dim query As String = "%SystemDrive%"
        Dim sourceFile As String = "\WINDOWS\PCHealth\HelpCtr\Binaries\helpctr.exe"
        str = Environment.ExpandEnvironmentVariables(query)
        System.Diagnostics.Process.Start("str + sourceFile")

Any help or even suggestion would really be appreaciated. :D
Thank You
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,602
Location
Norway
Programming Experience
10+
Here you are using variables that represent some string values:
VB.NET:
My.Computer.FileSystem.CopyFile(origFile, [COLOR=darkgreen]str + copiedFile[/COLOR])

Your other code you mistake by inputting a meaningless new string:
VB.NET:
My.Computer.FileSystem.CopyFile(origFile, [COLOR=red]"str + copiedFile")[/COLOR]
 

oceaniana

Member
Joined
Apr 1, 2006
Messages
11
Programming Experience
Beginner
Hi

Thank you for your reply

the top code orig post i figured out to get it to work, the below does work. But i dont know where the worthless string is though

VB.NET:
[LEFT]      Dim str As String
      Dim origFile As String = "1"
      Dim query As String = "%SystemDrive%"
      Dim copiedFile As String = "\Register.key"
      str = Environment.ExpandEnvironmentVariables(query)
      My.Computer.FileSystem.CopyFile(origFile, str + copiedFile)[/LEFT]

NEW TASK, im now trying to just execute this file with a sys variable and its not working, below code is close to working i just can't figure out what is wrong

VB.NET:
        Dim str As String
        Dim query As String = "%SystemDrive%"
        Dim sourceFile As String = "\WINDOWS\PCHealth\HelpCtr\Binaries\helpctr.exe"
        Dim addEmUp As String = "str + sourceFile"
        Str = Environment.ExpandEnvironmentVariables(query)
        Process.Start("addEmUp")


Extra info, on the top example, the out put for Auto window is as follows
query "%SystemDrive%" String
sourceFile "\WINDOWS\PCHealth\HelpCtr\Binaries\helpctr.exe" String
str "E:" String
Add em together and the path is corect and does exist (E:\WINDOWS\PCHealth\HelpCtr\Binaries\helpctr.exe), im a noob, and lost as why this is happening, in perl u can get it to out put the error in a browser, is there some way of adding some code to get the path it has generated and to output the error somewhere in visual studio????

Thanks
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,602
Location
Norway
Programming Experience
10+
that's exactly what I'm saying, you have to see the difference between
str + sourceFile (using string variables)
and
"str + sourceFile" (meaningless string)

(you could also read the book ;) )
 

oceaniana

Member
Joined
Apr 1, 2006
Messages
11
Programming Experience
Beginner
Thank You, Thank You, Thank You, Thank You, Thank You, Thank You, Thank You, Thank You, JOHN :D

Below code works

VB.NET:
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] str [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] query [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#800000]"%SystemDrive%"
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] sourceFile [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#800000]"\WINDOWS\PCHealth\HelpCtr\Binaries\helpctr.exe"
[/COLOR][/SIZE][SIZE=2]Str = Environment.ExpandEnvironmentVariables(query)
System.Diagnostics.Process.Start(str + sourceFile)
[/SIZE][/COLOR][/SIZE][SIZE=2]
[/SIZE]

Thank You All
Places ive been for help
http://www.vbdotnetforums.com/showthread.php?t=9552
http://www.vbcity.com/forums/topic.asp?tid=124109
http://p2p.wrox.com/topic.asp?TOPIC_ID=42262
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=328521&SiteID=1
 
Last edited:
Top Bottom