cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
atulmaurya
Level 6

Checking logged user...

Hi,
I am creating an InstallAnywhere project for windows platform. I want to check if the currently logged user has adminrights or not. If not the setup will exit. Also the user should not be admin. It should be a local user with admin rights. Can anyone help me to find the solution.

Thanks.
Labels (1)
0 Kudos
(14) Replies
pv7721
Level 20

Please see the InstallAnywhere API documentation, there are APIs that have inherited from InstallShield, there is a method to check if the local user is admin on Windows.
0 Kudos
atulmaurya
Level 6

hi,
Actually I am using demo version of InstallAnywhere 2010. When I extract IAClasses.zip, i dont get all the classes of InstallShield API mentioned in JavaDoc (Ex- SecurityService). In the Service subdirectory there is only one class ServiceException, all other are missing. Can you explain this problem.

Thanks.
0 Kudos
pv7721
Level 20

Those classes are not in IAClasses.zip but in a different service.jar I think. But I was saying to read the doc, I'm not sure I understand what's the use to you to check directly the classes.
0 Kudos
atulmaurya
Level 6

Hi pv7721,

to check wheather th logged user is admin I am using the code:

SecurityService service = (SecurityService) ruleProxy
.getService(SecurityService.class);
boolean isAdmin = false;
try {

// Check if the logged user has admin rights
isAdmin = service.isCurrentUserAdmin();
} catch (ServiceException e) {

System.out.println("Exception occured: " + e);
return false;
}

return isAdmin;

I compiled it and added the class file to zip bt its not getting executed is there any problem with the logic.

Thanks alot...
0 Kudos
pv7721
Level 20

I'm afraid you need to read a little bit more about how IA works. You're not suppose to modify IAClasses.zip, but build your own .jar with the compiled class, and use Execute Custom code action!
0 Kudos
madhavbantwal
Level 6

Hi atulmaurya,

I recommend you to do the following.

Check how a custom rule is written from the sample templates which Installanywere offers you in location where you have installed it.

1.create a .jar file of the compiled class file
2.Navigate to Project-->Rules in the Advanced Designer view
3.Select the Custom Rule and Add the .jar file you created along with its main class name
4.Now Build the project along with your other requirement and try installing it

If you have logged in as admin the rules evaluates to true and the installer proceeds with its execution else terminates

Thanks,

Madhav Pai
Engineering InstallAnywhere
Flexera Software
0 Kudos
atulmaurya
Level 6

hi,
I am using the process mentioned by you. But not gettig the desired result. One thing that I am not getting is that I am using the classes IAclasses.zip and service.jar. Do I need to sign these jars and add in "Configure Dependencies" or InstallAnywhere will automatically detect them because these are inbuild jars in InstallAnywhere.


Thanks
0 Kudos
pv7721
Level 20

Normally, the IaClasses.zip is automaticall added, but you need to check Project/Java Add service support for custom code.
0 Kudos
atulmaurya
Level 6

hi Vlad,
finally i am able to run my first custom rule in InstallAnywhere. Its just returning true/false (not any complex logic).

But when it comes to the rule that I need to write (checking logged user) I am using following code:



import com.installshield.wizard.service.ServiceException;
import com.installshield.wizard.service.security.SecurityService;
import com.zerog.ia.api.pub.CustomCodeRule;

public class AdminWizardBeanRule extends CustomCodeRule {

public boolean evaluateRule() {

boolean isAdmin = true;

try {

// Get the reference to the SecurityService
SecurityService service = (SecurityService) ruleProxy
.getService(SecurityService.class);
// Check if the logged user has admin rights
isAdmin = service.isCurrentUserAdmin();

} catch (ServiceException e) {

System.out.println("Exception occured: " + e);
return false;
}

return isAdmin;
}

public static void main(String args[]) {

AdminWizardBeanRule admin = new AdminWizardBeanRule();
System.out.println(admin.evaluateRule());
}
}







but this code is generating NullPointerException at line:


SecurityService service = (SecurityService) ruleProxy
.getService(SecurityService.class);


But in Java doc its mentioned that CustomCodeRuleProxy object can be referenced by ruleProxy. Can you please tell whats the problem with this code and why its generating that exception. I will be really thankful if you can suggest some solution.

Thanks alot
0 Kudos
madhavbantwal
Level 6

hi atulmaurya,

Please use this script i have tuned it up.

import com.installshield.wizard.service.ServiceException;
import com.installshield.wizard.service.security.SecurityService;
import com.zerog.ia.api.pub.CustomCodeRule;

public class AdminWizardBeanRule extends CustomCodeRule
{
public boolean evaluateRule()
{
boolean isAdmin = true;
try
{
SecurityService service = (SecurityService) ruleProxy.getService(SecurityService.class);
isAdmin = service.isCurrentUserAdmin();
}
catch (ServiceException e)
{
System.out.println("Exception occured: " + e);
return false;
}
return isAdmin;
}
}

Please Make sure your IAClasses.zip and services.jar are in the path before you create the your own custom jars for the above rule.


Kindly let me know if this works.


Thanks,

Madhav Pai
0 Kudos
atulmaurya
Level 6

Hi Madhav,
Its not working. Actually this is the script that I was using. I had added main to check the script. Its generating the NullPointerException in the line where we are creating the object og SecurityService. What I think its not creating the object of SecurityService (but it should because this is the only method to create the object of any service in CustomCodeRuleProxy mentioned in JavaDoc).

Anyways thanks alot for your support....
0 Kudos
atulmaurya
Level 6

The problem could be the ruleProxy is not referencing to CustomCodeRuleProxy object. When i printed ruleProxy, it was null. Can you suggest some solution.


Thanks
0 Kudos
atulmaurya
Level 6

Hi,
can anyone help me with the (above) issue. I am using the evaluation version and this problem has killed alot of my valuable time (21 days).


Thanks
0 Kudos
madhavbantwal
Level 6

Hi atulmaurya,

Install Anywhere 2011 is available. I Request you to evaluate the latest Version and Check the Configuration your currently trying out in Install Anywhere 2010 Evaluation.

Please Try out the following link

http://www.flexerasoftware.com/resources/trials.htm#installanywhere

Thanks,
Madhav Pai
0 Kudos