@@ -141,7 +141,7 @@ -(void)AuthorizeCreate
141141 UInt32 count = (UInt32)[list count ];
142142 AuthorizationItem authItem[count];
143143 AuthorizationRights authRights;
144- AuthorizationFlags flags = kAuthorizationFlagDefaults |
144+ AuthorizationFlags flags = kAuthorizationFlagDefaults |
145145 kAuthorizationFlagInteractionAllowed |
146146 kAuthorizationFlagPreAuthorize |
147147 kAuthorizationFlagExtendRights ;
@@ -169,97 +169,22 @@ -(void)AuthorizeCreate
169169
170170
171171
172-
172+ // 虽然要被分离,但是我觉得最好用。
173173-(void )AuthorizeExeCmd : (NSString *)file
174174{
175- // 虽然要被分离,但是我觉得最好用。
176- OSStatus status_exe = AuthorizationExecuteWithPrivileges (self->_authRef , (void *)[file cStringUsingEncoding: NSASCIIStringEncoding], kAuthorizationFlagDefaults , nil , nil );
175+ #pragma clang diagnostic push
176+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
177+
178+ char *args[] = {NULL };
179+ OSStatus status_exe = AuthorizationExecuteWithPrivileges (self->_authRef , (void *)[file cStringUsingEncoding: NSASCIIStringEncoding], kAuthorizationFlagDefaults , args, nil );
177180 if (status_exe != errAuthorizationSuccess)
178181 {
179182 NSLog (@" AuthorizationExecuteWithPrivileges failed!:%d " , status_exe);
180183 return ;
181184 }
185+ #pragma clang diagnostic pop
182186}
183187
184- // -(void)AuthorizeFile:(NSString *)file
185- // {
186- // NSString *testFile = file;
187- // AuthorizationItem authItem = { kAuthorizationRightExecute, [testFile length], (void *)[testFile cStringUsingEncoding:NSASCIIStringEncoding], 0};
188- // AuthorizationRights authRights = {1, &authItem};
189- // AuthorizationFlags flags = kAuthorizationFlagDefaults |
190- // kAuthorizationFlagInteractionAllowed |
191- // kAuthorizationFlagPreAuthorize |
192- // kAuthorizationFlagExtendRights;
193- //
194- // if (self->_authRef) {
195- // NSLog(@"ok");
196- // }else{
197- // OSStatus status = AuthorizationCreate(&authRights, kAuthorizationEmptyEnvironment, flags, &self->_authRef);
198- // if(status != errAuthorizationSuccess)
199- // {
200- // NSLog(@"AuthorizationCreate failed!");
201- // return;
202- // }else{
203- // NSLog(@"AuthorizationCreate ok!");
204- // }
205- // }
206- // OSStatus status_exe = AuthorizationExecuteWithPrivileges(self->_authRef, authItem.value, kAuthorizationFlagDefaults, nil, nil);
207- // if (status_exe != errAuthorizationSuccess)
208- // {
209- // NSLog(@"AuthorizationExecuteWithPrivileges failed!");
210- // return;
211- // }else{
212- // NSLog(@"运行成功");
213- // }
214- // }
215-
216- // -(void)AuthorizeFile2:(NSString *)file
217- // {
218- //
219- // BOOL result = NO;
220- // NSError * error = nil;
221- //
222- // OSStatus status = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &self->_authRef);
223- //
224- // NSLog(@"%d", status);
225- // if (status != errAuthorizationSuccess) {
226- // /* AuthorizationCreate really shouldn't fail. */
227- // NSLog(@"获取权限失败!!");
228- // assert(NO);
229- // self->_authRef = NULL;
230- // }
231- //
232- // AuthorizationItem authItem = { kSMRightModifySystemDaemons, 0, NULL, 0 };
233- // AuthorizationRights authRights = { 1, &authItem };
234- // AuthorizationFlags flags = kAuthorizationFlagDefaults |
235- // kAuthorizationFlagInteractionAllowed |
236- // kAuthorizationFlagPreAuthorize |
237- // kAuthorizationFlagExtendRights;
238- // OSStatus statusR = AuthorizationCopyRights(self->_authRef, &authRights, kAuthorizationEmptyEnvironment, flags, NULL);
239- //
240- // if (statusR != errAuthorizationSuccess) {
241- // NSLog(@"获取权限失败!!!");
242- // error = [NSError errorWithDomain:NSOSStatusErrorDomain code:status userInfo:nil];
243- // } else {
244- // NSLog(@"获取权限成功");
245- // CFErrorRef cfError;
246- //
247- // /* This does all the work of verifying the helper tool against the application
248- // * and vice-versa. Once verification has passed, the embedded launchd.plist
249- // * is extracted and placed in /Library/LaunchDaemons and then loaded. The
250- // * executable is placed in /Library/PrivilegedHelperTools.
251- // */
252- // result = (BOOL) SMJobBless(kSMDomainUserLaunchd, (CFStringRef)@"test", self->_authRef, &cfError);
253- // if (!result){
254- // error = CFBridgingRelease(cfError);
255- // }
256- //
257- // if ( ! result) {
258- // assert(error != nil);
259- // NSLog(@"%@", error);
260- // }
261- // }
262- // }
263188
264189#pragma mark 获取进程
265190-(void )getProcess
0 commit comments