|
-
September 6th, 2001, 04:56 AM
#1
access to environment variables
Hi
Does anyone know how to access dos-environment-variables in vb?
I want to check if there´s a certain ocx in the
"%windir%\system32"
Thank you
-
September 6th, 2001, 05:48 AM
#2
Re: access to environment variables
To get the system path, you can use the GetSystemDirectory API
private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (byval lpBuffer as string, byval nSize as Long) as Long
private Sub Form_Load()
Dim strPath as string
strPath = Space(255)
GetSystemDirectory strPath, 255
MsgBox strPath
End Sub
Tom Cannaerts
[email protected]
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
-
September 6th, 2001, 07:30 AM
#3
Re: access to environment variables
Hi
Thanks for your answer.
But i still got a little problem.
Using your code i´ve got "c:\winnt\system32"
in strPath. The next thing i want to do is to check if thers a mswinsck.ocx in that directory.
I tried it the following way:
dim d,x as string
x=strPath+"\mswinsck.ocx"
d=dir(x)
if(d="mswinsck.ocx")then
...
end if
This doesnt work. The problem is that
d=strPath+"\mswinsck.ocx"
doesnt work. d still only contains "c:\winnt\system32".
I guess this is because of all the spaces at the end of strPath, but i dont know how to fix that
(i already tried strPath=trim(strPath)).
Thank you
@Cakkie
PS: I´ve also send you sent you this message as a private message by mistake. Sorry for that.
-
September 6th, 2001, 07:32 AM
#4
Re: access to environment variables
I already replied to you private message 
use & in stead of +
x = strPath & "\mswinsock.ocx"
Tom Cannaerts
[email protected]
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
-
September 6th, 2001, 07:49 AM
#5
Re: access to environment variables
Still doesnt work.
I can add a string in front of srtPath
but not on the end of it.
x="xxx" & strPath works
x=strPath & "xxx" doesnt
???
-
September 6th, 2001, 08:00 AM
#6
Re: access to environment variables
I reviewed my code and discovered a bug. The GetSystemDirectory function returns a null-terminated string. this is why you cannot append, cause null and something = null.
This should fix the problem. Place this line after the call to GetSystemDirectory
strPath = Left(strPath, len(Trim(strPath)) - 1)
Tom Cannaerts
[email protected]
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
-
September 6th, 2001, 08:46 AM
#7
Re: access to environment variables
Thats not really a bug. Most, if not all APIs that handle strings, Fill the space allocated for strings with nulls to avoid left over garbage in the data area for the string.
John G
-
September 6th, 2001, 08:50 AM
#8
Re: access to environment variables
Try this to read DOS environment
Private Sub Command1_Click()
Dim Env As String
Dim x As Integer
Dim t As String
x = 1
Env = Environ(x)
Do Until Env = ""
Env = Environ(x)
Print t; Env
x = x + 1
Loop
End Sub
Iouri Boutchkine
[email protected]
-
September 6th, 2001, 08:51 AM
#9
Re: access to environment variables
Also try this
Code: Environ("<Param>")
Returns a string, where <Param> can be any of the following:
ALLUSERSPROFILE
APPDATA
CommonProgramFiles
COMPUTERNAME
ComSpec
HOMEDRIVE
HOMEPATH
LOGONSERVER
NUMBER_OF_PROCESSORS
OS
Os2LibPath
Path
PATHEXT
PROCESSOR_ARCHITECTURE
PROCESSOR_IDENTIFIER
PROCESSOR_LEVEL
PROCESSOR_REVISION
ProgramFiles
SystemDrive
SystemRoot
TEMP
TMP
USERDOMAIN
USERNAME
USERPROFILE
windir
If you wish to dump all of the environment variables, this simple piece
of code will work:
For i = 1 To 26
Debug.Print Environ(i) & vbCrLf
Next i
Iouri Boutchkine
[email protected]
-
February 14th, 2002, 12:22 PM
#10
Re: access to environment variables
How do you go about setting environment variables from VB? Does environ have a matching function to do this?
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
If the only tool you have is a hammer you will
tend to see all problems as nails
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|