OK, i got it working, for some reason i had to remove the "not" from the following line:
if @error=0 and not primapstate("\\server1\printer2")
After that i tested it and it worked. Thanks for all the help.