Access denied when using system() function.

I found the VBS file in system 32 folder for managing IIS6 metabase - its called iisweb.vbs and now im trying the following...

function Batch_File_Gen ($UserName,$DomainName){
     if (file_exists('jobs'.'/'.$UserName.'_'.$DomainName.'.bat')){
     die ('Error:  Batch File Already Exists - Website has probably already been generated!');
     }else{
          if (file_exists ('../../' . $UserName)){
          $Data = 'Iisweb /create D:\\websites\\whatever\\' . $UserName . ' "' . $DomainName . '" /d www.' . $DomainName;
          $fp = fopen ('jobs' . '/' . $UserName . '_' . $DomainName . '.bat',"w");
          fwrite ($fp,$Data);
          fclose ($fp);
          }else{
          die ('Error:  Username does not exist.  Please check and try again.');
                //because if username exists they will already have their own directory...
          }
     }
}

In another function i use system(); function to execute the batch files created using the above function... and it works!!  The only problem now is this:

-----------------------------
You cannot run this command because you are not an administrator on the server you are trying to configure.

-2147024891
-----------------------------

I tried giving IUSR_PCNAME admin rights to iisweb.vbs - and I still get the same error.  I also tried doing "runas" in the bacth file and still cant get access.  I even tried editing the vbs file to remove the access check altogether (risky but despeate).  This is where I got really confused - after commenting out the lines that check permission and saving the file - i still get the same error, so I went back to see the VBS file and the changes i had made had dissapeared!!!  Does Windows think I am a hacker and is it automatically restoring iisweb.vbs?

If I can prevent that then im sure the code will work fine...

Thanks for your help!

NIPPLES
LVL 3
NIPPLESAsked:
Who is Participating?
 
Joseph MelnickConnect With a Mentor Senior Software Developer - Pharmacy ApplicationsCommented:
The Guy that was maintaining the pecl package and helped me was Frank Kromann you can see his tutorial on his homepage at: http://kromann.info/php.php

Joseph
0
 
Joseph MelnickSenior Software Developer - Pharmacy ApplicationsCommented:
Hello NIPPLES,

Have you looked at LIX. IIS Administration Functions?

There is a PHP extension for handling IIS administration for you.

http://www.php.net/manual/en/ref.iisfunc.php

Joseph Melnick
0
 
NIPPLESAuthor Commented:
Hi Joseph,

Thanks for pointing that out.  I just gave it a try and cant get it to work.  I am guessing that it doesnt work with IIS6.  I downloaded the dll file and adjusted php.ini correctly.  There are no errors about loading the extension - it does get loaded - just it doesnt do anything when i use the functions.

Im now this far with my "batch file generator" approach...

function Batch_File_Gen ($UserName,$DomainName){
      
            if (file_exists ('../../' . $UserName)){
            $Data = 'echo Generating Website From: ' . 'D:\\websites\\whatever\\' . $UserName . ' To: ' . $DomainName . "\r\n";
            $Data = $Data . 'Iisweb /create D:\\websites\\jv500\\' . $UserName . ' "' . $DomainName . '" /d www.' . $DomainName . ' >> ' . date("d_m_y") . '_executed.txt' . "\r\n";
            $Data = $Data . 'echo Adding Host Header For: ' . $DomainName . ' so it can also resolve from:  www.' . $DomainName . "\r\n";
            $Data = $Data . 'cscript //nologo translate.js "' . $DomainName . '" > siteid.txt' . "\r\n";
            $Data = $Data . 'for /f %%I in (siteid.txt) do SET SITEID=%%I' . "\r\n";
            $Data = $Data . 'Adsutil set w3svc/%SITEID%/serverbindings "202.190.198.11:80:www.' . $DomainName . '" ":80:www.' . $DomainName . '"' . "\r\n";
            $Data = $Data . 'Adsutil set w3svc/%SITEID%/serverbindings "202.190.198.11:80:' . $DomainName . '" ":80:www.' . $DomainName . '"' . "\r\n";
            $Data = $Data . 'Del siteid.txt' . "\r\n";
            $FileName = 'jobs' . '/' . date("d_m_y") .'.bat';
            $fp = fopen ($FileName,"a+");
            fwrite ($fp,$Data);
            fclose ($fp);
            print '<h3><b>Configuration saved as jobs' . '/' . date("d:m:y") .'.bat</b></h3><br>';
            print 'Configuration file now reads: <br><pre>';
            readfile ('jobs' . '/' . date("d_m_y") .'.bat');
            print '</pre><hr>Thank you,<br><em>Server Robot V1.0</em>';
            }else{
            die ('Error:  Username does not exist.  Please check and try again.');
            }
      
}

I have tested running the batch file and it works but im still disapointed i cant use system() to call the batch file.  Now everyday a batch file is created manually by an admin staff by using the above function - and i will still have to log in and directly run the batch file daily :o(

If I can just get the batch file to execute then it mission is completed!  Any ideas?

NIPPLES
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
Joseph MelnickSenior Software Developer - Pharmacy ApplicationsCommented:
I got some help a long while ago by the creator of that dll and I go it working properly. I recently lost my HD so I do not have those notes but I suspect that the anonymous internet user IUSER_* still does not have sufficient permission to execute functions contained therein. The DLL is loaded by the webserver process which has permission but the functions contained in teh DLL are system administration functions.

Hope thiis helps.

Joseph
0
 
NIPPLESAuthor Commented:
Hi Joseph,

Ah i see...  Possible work around is to call a custom VB program using the system command that in turn will execute the batch file!  I dont think it will fool the server but its worth a try...  

NIPPLES
0
 
NIPPLESAuthor Commented:
Nope... same problem there...

Maybe a rewrite of  iisweb.vbs and saving as a new file in new location with looser access permissions will work - rather than using the actual  iisweb.vbs (and getting access denied when exected from phps system() function....

0
 
NIPPLESAuthor Commented:
Hi jmelnick,

I managed to do a work around by using the batch file approach.  I schedule the batch files to run every hour on the server and the php web app generates the batch files for adding / removing websites in iis6.  

I still could not get the method you suggested to work - although it would be better as less layers of programs involved.

Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.