Área de trabalho
8) Oi ! Gostaria de saber como criar um atalho no desktop do windows.
Por favor!
Por favor!
(conta Desativada)
Curtidas 0
Respostas
Nildo
01/06/2003
Coloque essas units na seção implementation :
uses ShlObj, ActiveX,ComObj, Registry;
Por último, crie uma procedure que faça o trabalho:
procedure CreateShortcut (FileName, Parameters, InitialDir, ShortcutName, ShortcutFolder : String);
var
MyObject : IUnknown;
MySLink : IShellLink;
MyPFile : IPersistFile;
Directory : String;
WFileName : WideString;
MyReg : TRegIniFile;
begin
MyObject := CreateComObject(CLSID_ShellLink);
MySLink := MyObject as IShellLink;
MyPFile := MyObject as IPersistFile;
with MySLink do
begin
SetArguments(Parameters);
SetPath(PChar(FileName));
SetWorkingDirectory(PChar(InitialDir));
end;
MyReg := TRegIniFile.Create(´Software\MicroSoft\Windows\CurrentVersion\Explorer´);
Directory := MyReg.ReadString (´Shell Folders´,´Desktop´,´´);
WFileName := Directory + ´\´ + ShortcutName + ´.lnk´;
MyPFile.Save (PWChar (WFileName), False);
MyReg.Free;
end;
uses ShlObj, ActiveX,ComObj, Registry;
Por último, crie uma procedure que faça o trabalho:
procedure CreateShortcut (FileName, Parameters, InitialDir, ShortcutName, ShortcutFolder : String);
var
MyObject : IUnknown;
MySLink : IShellLink;
MyPFile : IPersistFile;
Directory : String;
WFileName : WideString;
MyReg : TRegIniFile;
begin
MyObject := CreateComObject(CLSID_ShellLink);
MySLink := MyObject as IShellLink;
MyPFile := MyObject as IPersistFile;
with MySLink do
begin
SetArguments(Parameters);
SetPath(PChar(FileName));
SetWorkingDirectory(PChar(InitialDir));
end;
MyReg := TRegIniFile.Create(´Software\MicroSoft\Windows\CurrentVersion\Explorer´);
Directory := MyReg.ReadString (´Shell Folders´,´Desktop´,´´);
WFileName := Directory + ´\´ + ShortcutName + ´.lnk´;
MyPFile.Save (PWChar (WFileName), False);
MyReg.Free;
end;
GOSTEI 0
Vagner.oliveira
01/06/2003
Coloque essas units na seção implementation :
uses ShlObj, ActiveX,ComObj, Registry;
Por último, crie uma procedure que faça o trabalho:
procedure CreateShortcut (FileName, Parameters, InitialDir, ShortcutName, ShortcutFolder : String);
var
MyObject : IUnknown;
MySLink : IShellLink;
MyPFile : IPersistFile;
Directory : String;
WFileName : WideString;
MyReg : TRegIniFile;
begin
MyObject := CreateComObject(CLSID_ShellLink);
MySLink := MyObject as IShellLink;
MyPFile := MyObject as IPersistFile;
with MySLink do
begin
SetArguments(Parameters);
SetPath(PChar(FileName));
SetWorkingDirectory(PChar(InitialDir));
end;
MyReg := TRegIniFile.Create(´Software\MicroSoft\Windows\CurrentVersion\Explorer´);
Directory := MyReg.ReadString (´Shell Folders´,´Desktop´,´´);
WFileName := Directory + ´\´ + ShortcutName + ´.lnk´;
MyPFile.Save (PWChar (WFileName), False);
MyReg.Free;
end;
da erro ao compilar o programa:
[b]SetArguments(Parameters); [/b] --> incompatible types String and PChar
GOSTEI 0
Rômulo Barros
01/06/2003
Basta fazer o [b:2f291e88b4]Cast[/b:2f291e88b4]:
ou
:wink:
SetArguments(PAnsiChar(Parameters));
ou
SetArguments((Parameters As PAnsiChar));
:wink:
GOSTEI 0
Vagner.oliveira
01/06/2003
[quote:80de75d028=´Rômulo Barros´]Basta fazer o [b:80de75d028]Cast[/b:80de75d028]:
ou
:wink:[/quote:80de75d028]
e onde que eu coloco o comando para que crie o atalho :?:
SetArguments(PAnsiChar(Parameters));
ou
SetArguments((Parameters As PAnsiChar));
:wink:[/quote:80de75d028]
e onde que eu coloco o comando para que crie o atalho :?:
GOSTEI 0
Vitor Rubio
01/06/2003
Tenta o seguinte: nessa procedure, na parte que tá:
SetArguments(Parameters);
vc poe:
SetArguments(pansichar(Parameters));
assim vc pode passar os parametros como string, não precisa pchar. Se as outras variáveis também forem pchar faça a mesma coisa, eu não lembro se era.
Para criar o atalho, use:
SetArguments(Parameters);
vc poe:
SetArguments(pansichar(Parameters));
assim vc pode passar os parametros como string, não precisa pchar. Se as outras variáveis também forem pchar faça a mesma coisa, eu não lembro se era.
Para criar o atalho, use:
CreateShortcut (<nome do arquivo pro qual vc quer fazer atalho>, <parametros de execução do atalho>, <diretorio inicial do progr do atalho>, <nome do atalho>, <onde ficará o atalho>); Já usei essa procedure antes, se eu não me engano é assim ^^ espero ter ajudado!
GOSTEI 0