- Revenera Community
- :
- InstallAnywhere
- :
- InstallAnywhere Knowledge Base
- :
- Check whether the current user is admin or not through Evaluate custom rule
- Mark as New
- Mark as Read
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
Check whether the current user is admin or not through Evaluate custom rule
Check whether the current user is admin or not through Evaluate custom rule
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.