How to programatically detect what are all the drivers used in a labview VI, using its reference in another VI?
Well, using VI Server you can find all the SubVIs that a VI calls and their absolute paths. You can probably guess that if they are located in vi.lib, or user.lib folders that they are drivers. But this would be a guess only.
But if we use this code in another machine which doesn't contain the driver and if i give the VI's path as input to this code, I need to get all the drivers needed to be installed in that machine to make that VI work properly.
Ok, but what is the point? If you want to distribute application to other computers, create an installer including all required drivers.
I'm with the others. Build an EXE using the application builder in a project, then build an installer in the application builder in the project. When you configure the installer it has a section for Additional Installers, and will auto detect the other installers needed when installing it on a fresh machine (starting in LabVIEW 2014 I think). This will make one large installer that includes every thing needed to run that EXE on a machine that has no other NI software installed. I generally make a Full installer, and an Upgrade, where the Full includes all NI installers, and the Upgrade just includes the updated EXE and will only work on a machine that has had a Full installed at some point.