Autor Beitrag
Gast
Gast
Erhaltene Danke: 1



BeitragVerfasst: Do 07.08.03 14:24 
Downloadbar ist das ganze von:
assarbad.net/stuff/!export/reglink.txt

Man sollte immer von dort downloaden, da eventuell eine neuere Version online verfügbar ist!

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
(******************************************************************************
                               REGLINK.TXT v1.00

                           The code is PUBLIC DOMAIN
                 [ http://assarbad.net/stuff/!export/reglink.txt ]

 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                 Written and published by -=Assarbad=- (2003-08-07)

                              http://assarbad.net
                           Assarbad AT gmx DOT info
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 !!!!!!!!!!!!!!!!!This is considered to work on NT platform only!!!!!!!!!!!!!!!!

 -------------------------------------------------------------------------------
 It is recommended to check out the site: "http://www.ntinternals.net"
 for a way on how to delete symbolic links (aka REG_LINK).
 They use a method where the native API is being called. When trying to use the
 Win32 API with different flags I got bluescreens over and over. Therefore one
 should consider using the Native API.

 If I should find appropriate flags for deletion of REG_LINK I will update the
 source. If YOU find it, please let me know (but only if it is Win32 API!!! I 
 can write a Native API function myself - but ii's more excting here to find the
 proper flags with the Win32 API).
 -------------------------------------------------------------------------------

 Although my method uses the Win32 API, I use undocumented flags that are anyway 
 passed down to the Native API. That's why a cannot attest the correct function
 under all circumstances. It is more a prototype for studying REG_LINK. It's not 
 meant to be used directly without careful testing!

 Therefore: YOU HAVE TO KNOW WHAT YOU DO WHEN USING THIS SOURCE. BACKUP THE
 REGISTRY BEFORE TO NOT DAMAGE IT! I TAKE NO RESPONSIBILITY FOR ANY DAMAGE
 CAUSED BY THE USE OF THIS CODE!
 
 IF YOU SET IMPROPER PATHES AS LINK TARGET, THE RESULTING LINKS CANNOT BE 
 ACCESSED PROPERLY ANYMORE!

 ******************************************************************************)


{
const
  REG_OPTION_RESERVED         = $00000000; // Parameter is reserved
  REG_OPTION_NON_VOLATILE     = $00000000; // Key is preserved when system is rebooted
  REG_OPTION_VOLATILE         = $00000001; // Key is not preserved when system is rebooted
  REG_OPTION_CREATE_LINK      = $00000002; // Created key is a symbolic link
  REG_OPTION_BACKUP_RESTORE   = $00000004; // open for backup or restore special access rules privilege required
  REG_OPTION_OPEN_LINK        = $00000008; // Open symbolic link
}

const
  REG_OPTION_OPEN_LINK = $00000008; // Open unicode symbolic registry link

function CreateReglinkW(Keyname, LinkTarget: WideString): Boolean;
(*
  Creates a unicode symbolic link in the registry.
  That's why I called this function CreateRegLinkW() and not CreateRegLinkA().
  It will not work if you use a LinkTarget in ANSI format!!!

  Note: The format of the link target HAS TO BE in Windows NT native format.
        I am not sure wether this also implies that the function would only work
        on Windows NT and later.

        The Windows NT notion is, where Keyname lies in

        HKEY_LOCAL_MACHINE\Keyname -> \Registry\Machine\Keyname
        HKEY_USERS\Keyname         -> \Registry\User\Keyname

        The notion follows the common object namespace notion of NT.
*)

var
  key: HKEY;
  len, err: DWORD;
  data: Pointer;
begin
  Result := False;
  err := RegCreateKeyExW(HKEY_LOCAL_MACHINE, @keyname[1], 0, nil, REG_OPTION_CREATE_LINK, KEY_ALL_ACCESS, nil, key, nil);
  if err = ERROR_SUCCESS then
  try
    len := length(linktarget) * sizeof(WideChar);
    data := GetMemory(len + sizeof(WideChar));
    if Assigned(data) then
    try
      lstrcpynW(data, @linktarget[1], len + sizeof(WideChar));
      result := RegSetValueExW(key, 'SymbolicLinkValue', 0, REG_LINK, data, len) = ERROR_SUCCESS;
    finally
      FreeMemory(data);
    end;
  finally
    RegCloseKey(key);
  end;
end;

function SetReglinkW(Keyname, LinkTarget: WideString): Boolean;
(*
  Changes the LinkTarget of a symbolic link

  Parameters and conventions similar to CreateRegLinkW().
*)

var
  key: HKEY;
  len, err: DWORD;
  data: Pointer;
begin
  Result := False;
  err := RegCreateKeyExW(HKEY_LOCAL_MACHINE, @keyname[1], 0, nil, REG_OPTION_OPEN_LINK, KEY_ALL_ACCESS, nil, key, nil);
  if err = ERROR_SUCCESS then
  try
    len := length(linktarget) * sizeof(WideChar);
    data := GetMemory(len + sizeof(WideChar));
    if Assigned(data) then
    try
      lstrcpynW(data, @linktarget[1], len + sizeof(WideChar));
      result := RegSetValueExW(key, 'SymbolicLinkValue', 0, REG_LINK, data, len) = ERROR_SUCCESS;
    finally
      FreeMemory(data);
    end;
  finally
    RegCloseKey(key);
  end;
end;


//------------------------------------------------------------------------------
{
Here are two examples for calling the functions:

  if CreateRegLinkW('Software\!Testlink2', '\Registry\Machine\Software\Microsoft') then ;
  if SetRegLinkW('Software\!Testlink2', '\Registry\Machine\Software\Microsoft\Windows NT') then ;
}
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Fr 08.08.03 08:00 
Hallo!

Ist das jetzt eine Frage die du stellen willst oder eventl. ein neuer FAQ Beitrag? Beim letzeren wäre eine kurz Beschreibung von Vorteil. :wink: Außerdem würde ich es dann in die richtige Sparte verschieben.

Gruß
Tino
Gast
Gast
Erhaltene Danke: 1



BeitragVerfasst: Fr 08.08.03 16:04 
Hi Tino,

also ne CodeLibrary gibts hier nicht, daher wußte ich nicht wo einordnen. Und als oft gestellte Frage kann man es nun wahrlich nicht bezeichnen ;)
Da fällt es schwer sowas einzuordnen.

Luckie hatte in der DP auch gefragt was REG_LINKs nun eigentlich sind:

www.delphipraxis.net/viewtopic.php?t=8082

Was sind REG_LINKs:

zB HKEY_CURRENT_USER ist ein Symlink auf HKEY_USERS\S-R-I-S-S...

Wobei der rote Bereich die SID deines Accounts ist. So arbeitet auch mein LoggedOn um in Erfahrung zu bringen, wer eingeloggt ist.
MathiasSimmack
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 09.08.03 07:26 
Dann würde ich´s trotzdem in die FAQs schieben. Dort gibt es auch Dinge, die sicher nicht jeder häufig fragt ... :wink: ... die aber dennoch ganz interessant sind. Code-Lib hin oder her ...
Gast
Gast
Erhaltene Danke: 1



BeitragVerfasst: Sa 09.08.03 14:09 
Dann macht's doch ;)

Es obliegt doch den Mods und Admins das zu machen. Ich hab doch gesagt warum es hier gelandet ist. Wenn es in FAQ gehört dann los ;)


(
War für mich halt bloß nicht so ersichtlich - vielleicht könnte man da dran vielleicht gleich noch was machen. Damit es anderen nicht genauso geht

Vorschlag: "Delphi FAQ - Häufig gestellte Fragen und Quellcode-Schnipsel"

Codesnippets/CodeLibrary ... irgendwie sowas ;) ... den Rest find ich dann selber ;)
)

Meinen Segen habt ihr *g*
Ist die Frage beantwortet? Das Problem gelöst?

Dann klicke hier, um das Thema entsprechend zu markieren!