Marie, >Sorry, I have NO knowledge of Win NT. I have searched Delphi 5's help >and could not find 'GetEnvironmentVariable' but I did find it under the >SDK info - but I don't understand it at all!
The reference to WinNT was just to point out that this feature is associated with the protected, multiple login versions of windows and has been around a long time. GetEnvironmentVariable has nothing to do with Delphi, it is a Windows API function. "Windows NT and up" commonly refers to the protected versions of Windows. For example, there is another environment variable, OS, which contains Windows_NT for all the OS versions WinNT and up. Vista even has OS=Windows_NT. Here is a code stub you can use to get the idea about how to use the GetEnvironmentVariable API call: var EnvVar: string; Buf: PChar; BufSize, ExpandSize: integer; try EnvVar:='USERPROFILE'; {This is the environment variable we want to find} {Assume it will be 256 or less} BufSize:=256; Buf:=StrAlloc(BufSize); ExpandSize:=GetEnvironmentVariable(PChar(EnvVar),Buf,BufSize); {ExpandSize now contains that buffer size needed to return the value} if ExpandSize > Pred(BufSize) then begin {we overflowed the buffer, so go back and do it all over again} StrDispose(Buf); BufSize:=Succ(ExpandSize); Buf:=StrAlloc(BufSize); StrCopy(Buf,''); ExpandSize:=GetEnvironmentVariable(PChar(EnvVar),Buf,BufSize); end; {Assert: Buf now contains the value of the environment variable: USERPROFILE} finally StrDispose(Buf); end; I would recommend that you write a simple function that takes a string parameter and returns the value of the environment variable. >I also searched for >'Userprofile' and didn't find that either. Are these now functions in >Delphi 8 or Turbo Delphi (which I can't run since they require Win XP >and I'm still running Win 98)? None of this has anything to do with Delphi, it has to do with Windows. Older versions of Windows do not have a USERPROFILE environment variable that is setup by the operating system. So, when USERPROFILE is null, default to some predefined path. But if USERPROFILE is defined, you should assume that "C:\Program Files" may be protected. You may want to rethink ever putting data in the "C:\Program Files" directory. Glenn Lawler www.incodesystems.com -----Original Message----- From: Marie F Vihonsky [SMTP:[EMAIL PROTECTED] Sent: Tuesday, July 31, 2007 10:43 PM To: advanced_delphi@yahoogroups.com Subject: Re: [advanced_delphi] Re-Writing for Vista Hi Glenn, Sorry, I have NO knowledge of Win NT. I have searched Delphi 5's help and could not find 'GetEnvironmentVariable' but I did find it under the SDK info - but I don't understand it at all! I also searched for 'Userprofile' and didn't find that either. Are these now functions in Delphi 8 or Turbo Delphi (which I can't run since they require Win XP and I'm still running Win 98)? Marie Glenn B. Lawler wrote: > Mike, > > Running as Administrator does not really solve the problem. > Vista protects everything beneath the "C:\Program Files" directory. > This is simple to do in the right way, which has been in place since > Windows NT 4.0. The operating system maintains an environment > variable: USERPROFILE which is the PATH to a directory which is > private to the currently logged in user. In a batch file, you can > dereference the environment variable like this: > > CD /D %USERPROFILE% > > The statement above changes to the users private directory. > > When writing a program, the Windows API call: > GetEnvironmentVariable > > will return the value of an environment variable. > Check the Delphi help for details. > > Glenn Lawler > www.incodesystems.com > > -----Original Message----- > From: Mike [SMTP:[EMAIL PROTECTED] > Sent: Tuesday, July 31, 2007 4:13 PM > To: advanced_delphi@yahoogroups.com > Subject: Re: [advanced_delphi] Re-Writing for Vista > > the problem really is Vista - it changed all programs to run at a User > Level - it's easy enough to change - may not be the best way (at least in > M$'s eyes) > > right click on the desktop shortcut icon and change it to "Run as > Administrator" > > > ----- Original Message ----- > From: Marie F Vihonsky > To: Advance Delphi > Sent: Tuesday, July 31, 2007 3:35 PM > Subject: [advanced_delphi] Re-Writing for Vista > > > Hi All, > > I have just gotten the first glitches with Vista from users and it > involves the logic for writing to the databases and indexs. I'm still > of the old DOS mindset and a self-taught programmer. I have all my > files located under the main folder where the program is installed and > using Inno-Setup, I have the user install to: > c:\program files\myprogram > > Using Delphi 5, I can determine if the user has installed the program > somewhere else by determining where the EXE is located using this code: > exepath:=ExtractFilePath(Application.ExeName); > datapath := exepath + 'data\'; > if not DirectoryExists(datapath) then > if not CreateDir(datapath) then begin > raise Exception.Create('Cannot create '+ datapath); > exit; > end; > mdxpath := exepath + 'indexs\'; > if not DirectoryExists(mdxpath) then > if not CreateDir(mdxpath) then begin > raise Exception.Create('Cannot create '+ mdxpath); > exit; > end; > > Under Vista, I understand that this is a NO-NO since it requires write > permission from the Administer. Now my Users are all individual HOME > users, who are the Admins and don't know how to set-up their pc's to run > the program they way it did under all previous versions of Windows. > > I'm at a loss, since I don't have a PC with Vista. Soon to be rectified > before I go nuts trying to answer questions from my users! > > Meanwhile, how should I re-write my programs? Where can I write from the > program so that the user doesn't need Admin privileges and how do I > determine the folder name? > > Marie