+ Post New Thread
Results 1 to 5 of 5
Scripts Thread, VBS/Batch file call a remote PHP file silently in Coding and Web Development; I'm going to start work on a quick and simple PHP/Windows logging script that will log every time a user ...
  1. #1

    Join Date
    Mar 2010
    Location
    shadowx@AllEvil:/
    Posts
    222
    Thank Post
    12
    Thanked 28 Times in 25 Posts
    Rep Power
    14

    VBS/Batch file call a remote PHP file silently

    I'm going to start work on a quick and simple PHP/Windows logging script that will log every time a user logs in and out of a PC as well as tie the events together so I can see whether or not a student logged off from a particular session.

    Anyhoo the PHP wont be an issue, the problem is simply getting that login event to the PHP receiver. There are two obvious solutions I see each with drawbacks. Option one is to make a publicly writeable CSV file on the LAMP server and have the batch file echo straight into it. It's the simplest option by far but the drawback is that to make the data "live" in PHP I would need to read directly from the CSV with a database used for archives, the problems with that are two fold. It's a massive security risk opening the whole server to a clever (albeit it VERY clever) user and files are single access so if the login script runs twice at the same time (IE two users log in) one of the sessions will lock the CSV meaning I get no data from the second session or a corrupted CSV.

    The second option which is by far the best is to have my login script hit a PHP page similar to "log.php?user=auser&machine=XYZ" the php will then error check and make the data safe and insert it into a database safely. This gives me safe, accurate data, multiuser/session support and error checking as well as live data when I view the log. The problem being I can't make a script to hit a remote PHP page.

    Under linux I could use "wget", I know wget exists for windows but it requires me to deploy wget to all the machines in the school then risk incomplete data if I miss a machine etc... so I am looking for a built in, windows standard for calling a remote webpage without triggering user response or a browser window. I don't need any feedback from the PHP script it will all be silent.

    Any ideas?

  2. #2
    ascott2's Avatar
    Join Date
    Nov 2007
    Posts
    187
    Thank Post
    18
    Thanked 39 Times in 31 Posts
    Rep Power
    21
    I think your best bet would be to try and create a HTTP request from your script. I don't use vbs but maybe look around for MSXML2.XMLHTTP, which I think vbs can create an object of and perform get requests on websites from.

  3. Thanks to ascott2 from:

    shadowx (6th July 2012)

  4. #3

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    10,053
    Thank Post
    3,584
    Thanked 1,123 Times in 1,025 Posts
    Rep Power
    377
    Long shot and not even sure if it will work but what about putting or placing wget into the netlogon share on a server that all machines can access and in the script you just need to use a unc path to the netlogon share ?

  5. Thanks to mac_shinobi from:

    shadowx (6th July 2012)

  6. #4

    Join Date
    Mar 2010
    Location
    shadowx@AllEvil:/
    Posts
    222
    Thank Post
    12
    Thanked 28 Times in 25 Posts
    Rep Power
    14
    Quote Originally Posted by ascott2 View Post
    I think your best bet would be to try and create a HTTP request from your script. I don't use vbs but maybe look around for MSXML2.XMLHTTP, which I think vbs can create an object of and perform get requests on websites from.
    That is pretty much exactly what I want to do, just trigger a http request, will do some googling on that library/function, thanks!

    Long shot and not even sure if it will work but what about putting or placing wget into the netlogon share on a server that all machines can access and in the script you just need to use a unc path to the netlogon share ?
    Genius, didn't even think of that... If wget works like we both (now) expect I can simply call it as an external exe and pass it the URL as an argument and bob's your uncle!

    Thanks to both, will have a google if I get a chance in between cable pulling

  7. Thanks to shadowx from:

    mac_shinobi (6th July 2012)

  8. #5

    Join Date
    Mar 2010
    Location
    shadowx@AllEvil:/
    Posts
    222
    Thank Post
    12
    Thanked 28 Times in 25 Posts
    Rep Power
    14
    Quote Originally Posted by ascott2 View Post
    I think your best bet would be to try and create a HTTP request from your script. I don't use vbs but maybe look around for MSXML2.XMLHTTP, which I think vbs can create an object of and perform get requests on websites from.
    You sir are a genius.

    The documentation for windows commands is crap! If you google a PHP function you get the PHP manual showing all the expected and optional parameters and examples. Google windows stuff and all you get is people showing off the fact they have microsoft certifications! Got there in the end and got this little bit of code for anyone else who is interested in doing something similar:
    Dim info
    Dim connection

    Set info = CreateObject("Wscript.Network")
    computer = info.ComputerName
    user = info.UserName

    Set connection = CreateObject("MSXML2.XMLHTTP")
    connection.open "GET", "http://172.16.0.20/logging/test.php?pc="&computer&"&user="&user, FALSE
    connection.send
    WScript.Echo "!!DEBUG!! Status is: " & connection.Status
    Firstly define the variables, gotta love VBS... -.-
    Use the info variable to get the logged in user and computer name
    Set up the http connection object, give it the URL to hit and the method (in this case GET, as all we need to do is request the data rather than POST data to the server) and include the USER and COMPUTER variables in the url for PHP to process
    Send the connection
    Then for debugging echo out the HTTP status code.

    Works a charm for me, so now the fun bit, I get to do some more PHP coding

  9. Thanks to shadowx from:

    mac_shinobi (9th July 2012)



SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 5
    Last Post: 1st July 2014, 09:34 AM
  2. Replies: 2
    Last Post: 21st October 2010, 09:29 AM
  3. VB.net and Calling Third Party Dlls
    By penfold_99 in forum Coding
    Replies: 2
    Last Post: 6th May 2009, 10:31 PM
  4. PHP file lists contents
    By blackcat in forum Web Development
    Replies: 1
    Last Post: 19th January 2008, 10:09 PM
  5. Replies: 4
    Last Post: 25th December 2006, 10:15 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •