# -*- coding: utf-8 -*- """ Created on Thu Jan 10 12:45:14 2013 @author: narasimhapbl.1863 """ import os import sys import subprocess from PyQt4 import QtGui class test(QtGui.QMainWindow): def __init__(self): super(test,self).__init__() self.but = QtGui.QPushButton(self) self.but.clicked.connect(self.GetUnc) def GetUnc(self): exist,path = self.GetUncSourcePath('z') print exist,path def GetUncSourcePath(self,driveLetter): """ This will return the UNC () path of the network drive Usage GetUncSourcePath('P:') """ UNC_Path = '' try: DriveToCheck = driveLetter[:1] if os.path.exists('%s:' % DriveToCheck): print 'checking %s: drive' % DriveToCheck process = subprocess.Popen(["net use","%s:" % DriveToCheck],stdout=subprocess.PIPE,shell=True) out,err = process.communicate() splitLines = out.splitlines() LineSplit = splitLines[1].split() UNC_Path = LineSplit[2] return (True,UNC_Path) else: QtGui.QMessageBox(QtGui.QMessageBox.Critical,'Drive Error','Drive Not Exists') return (False,None) except Exception as ex: QtGui.QMessageBox(QtGui.QMessageBox.Critical,'Drive Error',ex.message) return (False,None) if __name__=='__main__': app = QtGui.QApplication(sys.argv) win = test() win.show() sys.exit(app.exec_())