The following code will delete all records from table in database on server. import win32com.client connectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=database;Data Source=server;" query = "delete from table;" con = win32com.client.Dispatch(‘ADODB.Connection’) con.Open(connectionString) con.Execute(query) con.Close( ) Note: This code works on Windows only. You will also need to install excellent Python for Windows extensions (pywin32) by …
Tag Archive: script
Sep 28
How can I restart Windows service with Python?
First you need to install excellent Python for Windows extensions (pywin32) by Mark Hammond from http://sourceforge.net/projects/pywin32/. Then you can use the following code (that will restart the Print Spooler service). import win32serviceutil serviceName = "spooler" win32serviceutil.RestartService(serviceName) Note: this code was tested with Python 2.7 and version 216 of the pywin32 extensions.