View Full Version : Visual basic programming help !!!!!


codeman_cas
27-05-2009, 20:24
Hi people , i am writing a backup program for our machines at work and am a bit stuck on one bit if anyone can help.....

i am needing this software to work on different pcs and am wanting it to copy from the local users temp folder to a pen drive , the problem im having is i cant seem to find a variable that i can use to choose the local users folders , as you can imagine each machine has a different user .

there is one file called FATALERRORLOG.TXT that i need to copy from the temp folder

most of the machines are on XP and a very few on 2000 .

if anyones got some code i could use or just let me know it would be greatly appreciated

Mark

Magilla
27-05-2009, 21:22
Dunno much about VB, but in VC you can call

DWORD GetEnvironmentVariable(
LPCTSTR lpName, // address of environment variable name
LPTSTR lpBuffer, // address of buffer for variable value
DWORD nSize // size of buffer, in characters
);

No doubt there is some VB equivalent, I couldn't say I've never written any.

Anyways........

I beleive you can use the environment variable "USERPROFILE" on XP this relates directly to "C:\Documents and Settings\<current user>"

Alternatively, the variable "TEMP" appears to point to my user\temp folder, so you could just use that.

Does that help?

InTheUK
27-05-2009, 21:58
Magilla is correct, you can use any of the normal file open commands in VB and include %TEMP% to have Windows substitute the current user's temp folder. You can also use it if you are doing the copy by executing a shell command.

... open "%TEMP%\FATALERRORLOG.TXT" for reading ...

You can also get the temp folder programatically using FileSystemObject; you'll need to add a reference to the Script Control first though.

John
28-05-2009, 23:12
Dunno much about VB, but in VC you can call

DWORD GetEnvironmentVariable(
LPCTSTR lpName, // address of environment variable name
LPTSTR lpBuffer, // address of buffer for variable value
DWORD nSize // size of buffer, in characters
);

No doubt there is some VB equivalent, I couldn't say I've never written any.


Yes, there is a dedicated API viewer that comes with VB which declares all the windows API correctly using the VB syntax.

Sillysod
29-05-2009, 12:40
My.Computer.FIleSystem.SpecialDirectories.Temp
will return a string with the path you need.