Introduction :
This Article will helps you to understand the steps required to Check whether the current user is admin or not through Evaluate custom rule.
Instructions :
To Create/Evaluate custom rule follow these simple steps
Step1 : Open your InstallAnywhere project.
Step2 : Go to "Rules" -> "Code Rules".
Step3 : Click on "Add" to create a new code rule.
Step4 : Give your rule a name (e.g., "Check if current user is admin").
Step5 : Paste the following code into the code editor:
import com.zerog.ia.api.pub.CustomCodeRule;
import java.io.IOException;
public class AdminCheckRule implements CustomCodeRule {
@Override
public String getDefaultValue() {
return null;
}
@Override
public String execute() {
if (isAdmin()) {
return "User is admin";
} else {
return "User is not admin";
}
}
private boolean isAdmin() {
String osName = System.getProperty("os.name").toLowerCase();
if (osName.contains("windows")) {
try {
Process process = Runtime.getRuntime().exec("cmd.exe /c net session");
int resultCode = process.waitFor();
return resultCode == 0;
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
return false; // For non-Windows systems or if an exception occurs
}
}
Step6 : Click on "OK" to save the rule.
Step7 : Now, you can use this rule in your InstallAnywhere project. When you use it, a message box will only appear if the current user is an admin.
To use this rule:
Go to the location where you want to use this rule in your InstallAnywhere project.
Right-click on that location and choose "Add Action".
Select "Run custom code" from the list of actions.
In the properties for this action, select your custom code rule ("Check if current user is admin").
Configure any additional properties for your message box, such as the message to display.
Build and run your InstallAnywhere project. The message box will only appear if the current user is an admin.
Related Articles
Programmatically Determining Whether the Current User Is an Administrator or Root 5Number of Views FlexNet Code Insight ScriptRunner returns "Current user admin doesn't have script admin role" error 3Number of Views "Created By" field on a record may be set to the current user if the field is currently empty when the record is updated 4Number of Views Evaluate, Activate, and Run InstallShield, FLEXnet AdminStudio, and InstallShield Collaboration on a Tablet PC 3Number of Views Next Run date is shown as the current date for discovery & inventory rules that have no last run time 4Number of Views
Hi, I am Reva - Ask me anything.
No new updates
Thanks for the feedback!
Your feedback has been saved.Rate this response:
Add Additional feedback ( Optional )
Are you sure you want to cancel
the case creation?
Are you sure you want to cancel the case creation?
Are you sure you want to close this case
| Products | Region | Phone Numbers |
|---|---|---|
| FlexNet Operations FlexNet Embedded FlexNet Publisher FlexNet Connect FlexNet Code Insight InstallAnywhere InstallShield |
North America * |
+1 630-332-2513 (toll) +1 877-279-2853 (toll-free in North America) |
| Europe * |
+44 1925 944367 (toll) +44 800 047 8642 (toll-free in Europe) |
|
| Japan * | +81 3-4540-5335 (select option 2) | |
| Australia * |
+61 3 9895 2177 +61 1800 560 603 (toll-free in Australia) |
|
|
Usage Intelligence (formerly
Revulytics) Compliance Intelligence |
Please use the Case Portal to submit your support ticket or reach out to your Revenera contact. | |
Case id: 00001065
Activity: Status change: 2 hours ago