修改系统环境变量Path值后,输入系统命令为什么找不到 ( 积分: 20 )

M

mylj

Unregistered / Unconfirmed
GUEST, unregistred user!
我自己写了个函数,调用后,在命令行下输入 ipconfig 等系统命令,系统提示路径找不到,我在系统环境变量里去掉我加的路径(c:/program files/vtionoracle/bin)就可以显示ipconfig 命令内容。我的代码是这样写的,你帮我看一下有没有问题:
procedure Write_oraclekey(getCurpath:string);
var
Reg: TRegistry;
spath:string;
getsucc:Boolean;
tempstr:string;
begin
Reg := TRegistry.Create;
getsucc:=false;
try

Reg.RootKey := HKEY_LOCAL_MACHINE;
getsucc:=Reg.OpenKey('/SYSTEM/CurrentControlSet/Control/Session anager/Environment', False);
if getsucc then
begin
spath:=Reg.ReadString('Path');
tempstr:=copy(spath,length(spath),1);
if(tempstr<>';') then
spath:=spath+';'+getCurpath+'/bin'
else
spath:=spath+getCurpath+'/bin' ;

Reg.WriteString('Path',spath);
SetEnvironmentVariable(pchar('Path'),pchar(spath));
SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, integer(Pchar('Environment')));
end;
finally
Reg.closekey;
Reg.free;
end;
end;
我调用函数 Write_oraclekey('c:/program files/vtionoracle')后,用set
可以看到新设置的环境变量值,但为什么在命令行下输入其他的系统命令(如 ping ,ipconfig)等,系统提示找不到该命令。在系统环境变量中除去(c:/program files/vtionoracle/bin)路径,在命令行下,就可运行系统命令(ping ,ipconfig),这应该怎么办?
 
我自己写了个函数,调用后,在命令行下输入 ipconfig 等系统命令,系统提示路径找不到,我在系统环境变量里去掉我加的路径(c:/program files/vtionoracle/bin)就可以显示ipconfig 命令内容。我的代码是这样写的,你帮我看一下有没有问题:
procedure Write_oraclekey(getCurpath:string);
var
Reg: TRegistry;
spath:string;
getsucc:Boolean;
tempstr:string;
begin
Reg := TRegistry.Create;
getsucc:=false;
try

Reg.RootKey := HKEY_LOCAL_MACHINE;
getsucc:=Reg.OpenKey('/SYSTEM/CurrentControlSet/Control/Session anager/Environment', False);
if getsucc then
begin
spath:=Reg.ReadString('Path');
tempstr:=copy(spath,length(spath),1);
if(tempstr<>';') then
spath:=spath+';'+getCurpath+'/bin'
else
spath:=spath+getCurpath+'/bin' ;

Reg.WriteString('Path',spath);
SetEnvironmentVariable(pchar('Path'),pchar(spath));
SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, integer(Pchar('Environment')));
end;
finally
Reg.closekey;
Reg.free;
end;
end;
我调用函数 Write_oraclekey('c:/program files/vtionoracle')后,用set
可以看到新设置的环境变量值,但为什么在命令行下输入其他的系统命令(如 ping ,ipconfig)等,系统提示找不到该命令。在系统环境变量中除去(c:/program files/vtionoracle/bin)路径,在命令行下,就可运行系统命令(ping ,ipconfig),这应该怎么办?
 
顶部