The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: starzboy on March 31, 2009, 08:42:28 AM

Title: Get full path name
Post by: starzboy on March 31, 2009, 08:42:28 AM
Hi
i have a string "%windir%/cyz.bat"
how do i process this string to get full path name = C:\WINDOWS\cyz.bat ?

Please help.
Title: Re: Get full path name
Post by: jj2007 on March 31, 2009, 09:27:57 AM
include \masm32\include\masm32rt.inc

.data?
buffer db MAX_PATH dup(?)

.code
start:
invoke GetEnvironmentVariable, chr$("windir"), offset buffer, sizeof buffer
MsgBox 0, offset buffer, "%Windir%", MB_OK
exit

end start
Title: Re: Get full path name
Post by: starzboy on March 31, 2009, 10:16:54 AM
that means i will have to remove the "%" and make it "windir" before using GetEnvironmentVariable ?
i will have to cut strings in 2 parts, is there any other way out ?
Title: Re: Get full path name
Post by: ToutEnMasm on March 31, 2009, 01:08:31 PM
Hello,
There is also this form,
Quote
      ;include \masm32\include\advapi32.inc + lib
      ;include \masm32\include\shell32.inc + lib
      ; define in ShlObj.h
      SHGFP_TYPE_CURRENT equ 0
      CSIDL_COMMON_DOCUMENTS equ 02eh

      ;------- data ----
      Htoken dd 0
      Chemin db MAX_PATH + 1 dup (0)
      titre db "title",0
      ;----------- code -----------------------
      
      invoke OpenProcessToken,hInstance,TOKEN_READ,addr Htoken
      invoke SHGetFolderPath,NULL,CSIDL_SENDTO,Htoken,SHGFP_TYPE_CURRENT,addr Chemin      

The CSIDL_... are differents constants who give differents paths.
In this piece of code that you have to modify in your source, "chemin" is the variable where the returned path is written

Title: Re: Get full path name
Post by: ToutEnMasm on March 31, 2009, 01:12:30 PM
re,
the ""%windir%/cyz.bat" make a ref to batch file.
In a batch, you can use it directly.
Quote
SET BATCH=%windir%\cyz.bat
Title: Re: Get full path name
Post by: donkey on March 31, 2009, 04:40:13 PM
Try ExpandEnvironmentStrings (http://msdn.microsoft.com/en-us/library/ms724265(VS.85).aspx)
Title: Re: Get full path name
Post by: BlackVortex on March 31, 2009, 05:28:08 PM
Quote from: donkey on March 31, 2009, 04:40:13 PM
Try ExpandEnvironmentStrings (http://msdn.microsoft.com/en-us/library/ms724265(VS.85).aspx)
That (and ExpandEnvironmentStringsForUser) are a good find  :thumbu

Never heard of those before.