كيف تقوم بتعريف وظيفة PowerShell التي تتطلب رفع؟

جدول المحتويات:

فيديو: كيف تقوم بتعريف وظيفة PowerShell التي تتطلب رفع؟

فيديو: كيف تقوم بتعريف وظيفة PowerShell التي تتطلب رفع؟
فيديو: افضل 5 تمارين للاعب كرةالقدم في البيت⚽️🏠#shorts #odey_amin #footballshorts 2023, ديسمبر
كيف تقوم بتعريف وظيفة PowerShell التي تتطلب رفع؟
كيف تقوم بتعريف وظيفة PowerShell التي تتطلب رفع؟
Anonim
PowerShell يمكن أن يكون مفيدا للغاية لكثير من المهام اليومية كما هو ، ولكن إذا كنت بحاجة إلى تعديل بعض الوظائف مع مراعاة بعض الشيء من الأمان ، فكيف تقوم بتعريف وظيفة بحيث تتطلب الارتفاع؟ يجيب منتدى SuperWser Q & A اليوم عن سؤال قارئ غريب.
PowerShell يمكن أن يكون مفيدا للغاية لكثير من المهام اليومية كما هو ، ولكن إذا كنت بحاجة إلى تعديل بعض الوظائف مع مراعاة بعض الشيء من الأمان ، فكيف تقوم بتعريف وظيفة بحيث تتطلب الارتفاع؟ يجيب منتدى SuperWser Q & A اليوم عن سؤال قارئ غريب.

تأتي جلسة الأسئلة والأجوبة اليوم مقدمة من SuperUser ، وهي قسم فرعي من Stack Exchange ، وهو عبارة عن مجموعة من المنتديات على مستوى المجتمع المحلي على مواقع الأسئلة والأجوبة.

السؤال

قارئ SuperAser يريد Vlastimil معرفة كيفية تعريف وظيفة PowerShell التي تتطلب الارتفاع:

Since I cannot find any alternatives to Linux’s sudo elevation command, I have the following question. How do I define a PowerShell function that requires elevation, as in activating a UAC prompt on my Windows 8.1 Pro, 64-bit system? For example, say I run the following function:

With the following results:
With the following results:
Image
Image

To be completely clear, if I run PowerShell as “user”, then run the aforementioned function system-check, I want the function to elevate in order to be able to execute the command (I want the UAC prompt to appear).

كيف تحدد وظيفة PowerShell التي تتطلب الارتفاع؟

الاجابة

المساهم في SuperUser Ashton لديه الإجابة لنا:

To run a specific command from an elevated window:

For example:
For example:
To run a specific script from an elevated window:
To run a specific script from an elevated window:
To run an entire PowerShell session that prompts the UAC:
To run an entire PowerShell session that prompts the UAC:
Image
Image

A function to return $True or $False if the current window is running with elevated permissions:

To ensure a script is only run As Admin, add this to the beginning:
To ensure a script is only run As Admin, add this to the beginning:
Image
Image

In PowerShell v4.0, the above can be simplified by using a #Requires statement:

Image
Image

Source: Run with Elevated Permissions [SS64.com]

هل لديك شيء تضيفه إلى الشرح؟ الصوت قبالة في التعليقات. هل ترغب في قراءة المزيد من الإجابات من مستخدمي Stack Exchange الآخرين المحترفين بالتكنولوجيا؟ تحقق من موضوع المناقشة الكامل هنا.

موصى به: