qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] Preliminary qemu-ifup support for windows


From: consul
Subject: [Qemu-devel] Preliminary qemu-ifup support for windows
Date: Tue, 17 Jun 2008 18:05:35 -0700

Is anybody interested in supporting qemu-ifup/down scripts on Windows hosts?
Here is a quick and dirty hack allowing to run vbscripts on qemu startup and 
shutdown. For start I have scripts that enable/disable the TAP0 device when 
qemu starts and exits, removing the notification icon from the taskbar when 
qemu is not running. I know, this can be done other ways, but it still nice 
to have the icons available, when needed, and scripts can do more than that. 
I still have not yet figured out how to turn the notification icon off when 
the qemu is connected and running, except manually refreshing the network 
connections window, any idea?

Here is my hack:


$ svn diff
Index: vl.c
===================================================================
--- vl.c        (revision 4744)
+++ vl.c        (working copy)
@@ -8680,6 +8680,8 @@
             }
         }
     }
+#else
+    run_script("cscript qemu-ifdown.vbs");
 #endif
     return 0;
 }
Index: tap-win32.c
===================================================================
--- tap-win32.c (revision 4744)
+++ tap-win32.c (working copy)
@@ -659,11 +659,23 @@
         tap_win32_free_buffer(s->handle, buf);
     }
 }
+void run_script(char *script){
+    STARTUPINFO sinfo;
+    PROCESS_INFORMATION pinfo;
+    memset(&sinfo,0,sizeof(sinfo));
+    sinfo.cb = sizeof(sinfo);
+    sinfo.wShowWindow = SW_HIDE;
+    sinfo.dwFlags = STARTF_USESHOWWINDOW;
+    CreateProcess(0,script,0,0,0,0,0,0,&sinfo,&pinfo);
+    WaitForSingleObject(pinfo.hProcess,INFINITE);
+    CloseHandle(pinfo.hThread);
+    CloseHandle(pinfo.hProcess);
+}

 int tap_win32_init(VLANState *vlan, const char *ifname)
 {
     TAPState *s;
-
+    run_script("cscript qemu-ifup.vbs");
     s = qemu_mallocz(sizeof(TAPState));
     if (!s)
         return -1;
Index: sysemu.h
===================================================================
--- sysemu.h    (revision 4744)
+++ sysemu.h    (working copy)
@@ -69,6 +69,7 @@

 /* TAP win32 */
 int tap_win32_init(VLANState *vlan, const char *ifname);
+void run_script(char *script);

 /* SLIRP */
 void do_info_slirp(void);

--------------
And here is a sample qemu_ifup.vbs script (substitute "Disa&ble" for 
"En&able" for ifdown)

set sh = createobject("wscript.shell")

Dim obj 'As Shell
Dim f 'As Folder
Dim itm 'As ShellFolderItem
Dim ix 'As ShellFolderItem
Dim net 'As Folder
Dim v 'As FolderItemVerb

Set obj = CreateObject("shell.application")
Set f = obj.Namespace(3)

For Each itm In f.Items
If itm.Name = "Network Connections" Then
    Set net = itm.GetFolder
    For Each ix In net.Items
        If ix.Name = "TAP0" Then
            For Each v In ix.Verbs
                If v.Name = "En&able" Then
                    v.DoIt
                End If
            Next
            Exit For
        End If
    Next
    Exit For
End If
Next
WScript.Sleep 1000







reply via email to

[Prev in Thread] Current Thread [Next in Thread]