Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

rtsymlnk.c

Go to the documentation of this file.
00001 /*++ 00002 00003 Copyright (c) 1992 Microsoft Corporation 00004 00005 Module Name: 00006 00007 rtsymlnk.c 00008 00009 Abstract: 00010 00011 NT level registry symbolic link test program 00012 00013 Turns a key into a symbolic link. 00014 00015 rtsymlnk <KeyPath> <SymbolicLink> 00016 00017 Example: 00018 00019 rtsymlnk \Registry\User\The_User\Foo \Registry\User\The_User\Bar 00020 00021 Author: 00022 00023 John Vert (jvert) 29-Apr-92 00024 00025 Revision History: 00026 00027 --*/ 00028 00029 #include "cmp.h" 00030 #include <stdio.h> 00031 #include <stdlib.h> 00032 #include <string.h> 00033 00034 void 00035 __cdecl main( 00036 int argc, 00037 char *argv[] 00038 ) 00039 { 00040 NTSTATUS Status; 00041 OBJECT_ATTRIBUTES ObjectAttributes; 00042 UNICODE_STRING KeyName; 00043 UNICODE_STRING LinkName; 00044 UNICODE_STRING NullName; 00045 ANSI_STRING AnsiKeyName; 00046 ANSI_STRING AnsiLinkName; 00047 HANDLE KeyHandle; 00048 00049 // 00050 // Process args 00051 // 00052 00053 if (argc != 3) { 00054 printf("Usage: %s <KeyPath> <SymLink>\n",argv[0]); 00055 exit(1); 00056 } 00057 00058 RtlInitAnsiString(&AnsiKeyName, argv[1]); 00059 Status = RtlAnsiStringToUnicodeString(&KeyName, &AnsiKeyName, TRUE); 00060 if (!NT_SUCCESS(Status)) { 00061 printf("RtlAnsiStringToUnicodeString failed %lx\n",Status); 00062 exit(1); 00063 } 00064 00065 RtlInitAnsiString(&AnsiLinkName, argv[2]); 00066 Status = RtlAnsiStringToUnicodeString(&LinkName, &AnsiLinkName, TRUE); 00067 if (!NT_SUCCESS(Status)) { 00068 printf("RtlAnsiStringToUnicodeString failed %lx\n",Status); 00069 exit(1); 00070 } 00071 00072 printf("rtsetsec: starting\n"); 00073 00074 // 00075 // Open node that we want to make a symbolic link. 00076 // 00077 00078 InitializeObjectAttributes( 00079 &ObjectAttributes, 00080 &KeyName, 00081 OBJ_CASE_INSENSITIVE, 00082 (HANDLE)NULL, 00083 NULL 00084 ); 00085 00086 Status = NtCreateKey(&KeyHandle, 00087 KEY_READ | KEY_WRITE, 00088 &ObjectAttributes, 00089 0, 00090 NULL, 00091 0, 00092 NULL); 00093 if (!NT_SUCCESS(Status)) { 00094 printf("rtsymlnk: NtCreateKey failed: %08lx\n", Status); 00095 exit(1); 00096 } 00097 00098 NullName.Length = NullName.MaximumLength = 0; 00099 NullName.Buffer = NULL; 00100 00101 Status = NtSetValueKey(KeyHandle, 00102 &NullName, 00103 0, 00104 REG_LINK, 00105 LinkName.Buffer, 00106 LinkName.Length); 00107 if (!NT_SUCCESS(Status)) { 00108 printf("rtsymlnk: NtSetValueKey failed: %08lx\n",Status); 00109 exit(1); 00110 } 00111 00112 Status = NtClose(KeyHandle); 00113 if (!NT_SUCCESS(Status)) { 00114 printf("rtsymlnk: NtClose failed: %08lx\n", Status); 00115 exit(1); 00116 } 00117 00118 printf("rtsymlnk: successful\n"); 00119 }

Generated on Sat May 15 19:41:41 2004 for test by doxygen 1.3.7